   Keyboard Input Parsing
  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   
  If the input is happening too fast you could try buffered input, which shouldn't lose any information.   ;  I almost invariably use windows messages for input these days. Reliable.   ;  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?   ;  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.;Quote:Original post by CuppoJavaYeah, 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 =/)   ;  I use the GetAsyncKeyState API as once I got messed up with the different WM_KEYDOWN, KEYFIRST, KEYLAST, KEYUP etc messages.   