confused about keyboard input

BlitzPlus Forums/BlitzPlus Beginners Area/confused about keyboard input

laughing_man(Posted 2014) [#1]
Can someone please tell me the difference between keyhit, getkey and waitkey. I have checked the help file but they all seem the same to me. I know they are different but they just seem the same. I cannot figure what to use when?


Yasha(Posted 2014) [#2]
WaitKey pauses the application until a key is pressed, then returns the relevant ASCII code.

GetKey checks if a key was pressed in the past (since the key buffer was last cleared by such a test), and returns its ASCII code or zero. GetKey does not pause the application, hence the zero option.

KeyHit tests whether a specific key (identified by the scancode parameter) was pressed in the past, returning true or false. It also does not pause the application.

There's also KeyDown, which is like KeyHit but tests whether a key is still being pressed right now.


In general you will want to use KeyHit or KeyDown. GetKey and WaitKey are of extremely limited utility for a realtime game or app, and ASCII codes are a useless way to identify keys anyway (most keys either represent multiple characters, e.g. capital and lowercase, or don't represent a character at all) - scancodes are much better as they are just a UID for each actual button on the keyboard.


Who was John Galt?(Posted 2014) [#3]
Keyhit tells you if the specified key has been hit since you last polled it. This is generally what you use for key input in a game loop. The keyhit function always returns immediately.

Waitkey will wait and only return from the function when the key has been hit.

Getkey I think returns a value relating to any key pressed, rather than just checking the key you specify. (If I remember correctly).


laughing_man(Posted 2014) [#4]
Interesting. Thank you very much guys.