
One time key input
Posted Wednesday, 30 July, 2008 - 20:19 by flopoloco inHello, I 'm a bit struggling with a problem here... I have this piece of code which basically alters a boolean variable amongst the two available values.
if (Keyboard.[Key.Space]) this.alertState = !this.alertState;
The trick I want to achieve here, is not to check constantly for a key press but give it a shot only once!
That means that the above piece of code behaves like this, because my human timing cannot sync with the software update timing. ;-)
Updates: 1 2 3 4 n
Input: X X X X n
And I would like to achieve this:
Updates: 1 2 3 4 n
Input: X - - - n
Sorry for asking C# based (not OpenTK) questions.
Cheers!


Comments
Re: One time key input
If you are under Windows.Forms, you could use KeyDown events instead of the Keyboard device.
If you are under GameWindow, I think you'll have to roll your own "space pressed event" logic:
This way "alertState" only changes when the "Space key pressed" event occur.
(the word "pressed" is a little ambigous to me - "click" is more to-the-point but is used for the mouse input device in everyday language)
Re: One time key input
Or, you can use the KeyDown event of the keyboard device, just like Windows.Forms. :)
Re: One time key input
Ah.. Nice :)
Re: One time key input
Oops, I 've just seen one example in OpenTK (one that makes the user select Fullscreen or Window mode). Thanks anyway. ;-)