Jump to content
  • Advertisement
Sign in to follow this  
CuppoJava

Keyboard Input Parsing

This topic is 4489 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys, I'm programming a 2D fighter-esque game, and I'm running into a little difficulty parsing the keyboard controls. Would anyone volunteer to explain how they are doing it? I have a function called wasKeyPressed(), which returns whether a key has been pressed since the input was last polled. I do this by checking whether the key is DOWN in the current frame, and UP in the previous frame. Now this worked until I tried to do double-clicks and stuff. Often, the user is able to press, release, then press again the key during the same frame, in which case, I can't detect the double-press. Just wondering what everyone else is using in terms of keyboard control. Do you guys use polling methods such as wasKeyPressed() or isKeyDown()? or do you use a Event Listener interface? Thanks a lot for sharing your knowledge -Cuppo

Share this post


Link to post
Share on other sites
Advertisement
If the input is happening too fast you could try buffered input, which shouldn't lose any information.

Share this post


Link to post
Share on other sites
Yeah, I'm about to switch to using buffered inputs. I'm just wondering what's a nice clean way of doing it.

Do games ever use an event listener scheme for Keyboard controls?

eg. Attach a listener to the controller class, then have the controller class call the keyPressed(KeyEvent k), keyReleased(KeyEvent k) methods inside the listener?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I'm not developing a game, although what i'm developing could be used to create games. My system is event driven, so I do use observer/listeners to raise events that can be handled by user created script.

However, I don't rely on Windows messages because of the lag with keyboard repeat. My main loop polls the keyboard and then places events in an event queue to be processed by my core.

Share this post


Link to post
Share on other sites
Quote:
Original post by CuppoJava
Yeah, I'm about to switch to using buffered inputs. I'm just wondering what's a nice clean way of doing it.

Do games ever use an event listener scheme for Keyboard controls?

eg. Attach a listener to the controller class, then have the controller class call the keyPressed(KeyEvent k), keyReleased(KeyEvent k) methods inside the listener?


With the project I'm currently working on that is almost exactly what I am doing. I also use the OIS library so I can seamlessly move between Linux and Windows without having to alter the code (I don't think it has Mac support as of yet)

My project is driven by game states, and cGameManager and cGameState inherit from OIS::MouseListener, OIS::KeyboardListener and OIS::JoystickListener. This allows the current game state to handle all input messages seamlessly. If I need unbuffered input, its just a case of reading from the input device directly (admittedly my cInputManager class is a singleton =/)

Share this post


Link to post
Share on other sites
I use the GetAsyncKeyState API as once I got messed up with the different WM_KEYDOWN, KEYFIRST, KEYLAST, KEYUP etc messages.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!