No Raw Input Key Up If I Press The Key Fast Enough?

Started by
5 comments, last by SeanMiddleditch 7 years, 9 months ago

I was doing some game development on a different machine than usual when I noticed that keys would occasionally stick after I released them, causing my character to keep running. At first I thought it was a bug in the new framework I was using, but I was unable to reproduce it on another machine, and I tracked the problem back to the Raw Input events that were being fired.

If I tap a key quickly, then I see the key down event fire, but the key up event isn't firing until the next time I press a key (it doesn't need to be the same key). This seems to be the case for every key on this device (E7440).

Any suggestions on how to address this? How common is this sort of low-level issue in the wild?

Advertisement

If you are detecting events at the message-pump level, any missing events will be the result of buggy code. This should not happen otherwise.

If you are missing events further down the pipeline, such as in the game loop, then it is an error with how you log and track key events. Because you said that keys get stuck, it seems more likely to be something related to the message pump.

Ensure that you process all waiting messages before continuing with the game loop and that you never discard any messages.

You can check to see if it is a bug with the keyboard driver by seeing if the same problem can be replicated in any other program, such as Notepad. If not, then it is specifically related to how you process messages.

L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

I have managed to reproduce it in notepad. It doesn't happen when typing (probably because notepad uses the repeat events, which do not seem to be firing?), but the problem is visible with the alt key. Key down on alt will display underlines under the shortcut keys for the menu items, and key up will then highlight the first menu item (File). When I tap quickly tap alt, the shortcut underlines are displayed, but the menu item is never highlighted.

The fact that there are no repeat events seems strange. Are those generated by Windows, or the keyboard driver?

I can't reproduce the Notepad behaviour on Win10. Maybe I'm not quick enough?

There are a whole bunch of weird keyboard behaviours due to specifications changing over the years, with certain keys being entirely virtual or sharing scancodes, but I don't recall Alt being one of them.

Having said that, you don't seem to be the first with this problem: http://stackoverflow.com/questions/2226476/problems-detecting-alt-key-on-the-control-keyup-event

I would not expect you to be able to reproduce it because the problem seems to be specific to this one machine. I cannot reproduce it on my other machine.

I was just using the alt key in notepad to demonstrate that the problem exists at a lower level than my (or MonoGame's) input handling. The problem occurs with every key.
Sounds like the keyboard hardware is faulty.
Do you have Sticky keys or other accessibility features enabled on that machine?

Sean Middleditch – Game Systems Engineer – Join my team!

This topic is closed to new replies.

Advertisement