Menu

kbhit

Malcolm McLean

kbhit

For games it's no good to hang a character event listener off a window.

The best way of getting interactive character control seems to be to implement a kbhit() on the keyboard. The function simply queries whether a key is currently pressed or released. It's very easy to add under Windows, it's just a wrapper for GetAsynchkeyState(). Under Linux it's a bit more difficult, because Linux has a Unix remote terminal type model.
However X11 applications do get keypress and key release events, so we can intercept these to build
a kbhit().

The key codes are a problem. Keyboards differ from country to country, and the non-alphanumeric keys also vary from one model of computer to another. Games generally need arrow keys for moving the character about, plus a fire, and sometimes other keys - the actual glyph on the key doesn't matter much, but the keys need to be in convenient positions.
I think we've got to give Unicode plus arrow keys, and hope.

so

int bbx_kbhit(BABYX *bbx, int code);

Games will typically call kbhit on every frame. So if they need to detect a press and release, for example for a non-automatic gun, they just call bbx_kbhit() and store the state for the previous frame.


Related

Wiki: Home