PDA

Click to See Complete Forum and Search --> : GetKeyState


DarkMoose
Nov 11th, 2000, 01:49 PM
Does anyone know how to use GetKeyState to determine if a key is just tapped, rather than being held down?

kedaman
Nov 11th, 2000, 02:32 PM
To do that you need to check getasynckeystate very often, and store the state in a buffer. For several keys you just use an array and loop trough.

'what you do is get the keystate into a temporary variable
temp = GetAsyncKeyState(Key)
'then by xoring it against a state you will know if it has changed
'so by multiplying it with the original state as -1 for 0
'and 1 for 1, you still get unchanged state as 0
keyevent = (keystate Xor temp) * (temp - 0.5) * 2
keystate = temp

The result, keyevent is
-1 the key is pressed
1 the key is released
0 not changed