Detect key release?
BlitzMax Forums/BlitzMax Beginners Area/Detect key release?
| ||
| How do i go about to find out if a key on the keyboard has been released? I have a function i want to execute only one time on release (when input stops). So far the only solution i can come up with is to add to a counter or something while a key is pressed, and then check for any increment since the last frame, then if there is none i execute my function and reset the counter. But i cant help thinking there´s a better way? /Peter |
| ||
| you can use keyhit or GetChar() |
| ||
Depending on what you're doing it's usually as simple as:
Local KeyWasPressed:Int = False
'Main Loop:
While Not KeyHit(Key_Escape)
Local KeyIsPressed:int
KeyIsPressed = KeyDown(Key_X)
If (KeyIsPressed = False) And (KeyWasPressed = True) Then
'Do Stuff here, key has been released
EndIf
Flip() 'etc...
KeyWasPressed = KeyIsPressed
Wend
(haven't tested, just take it as pseudo-code). Last edited 2010 |
| ||
You can also use eventsSuperStrict Graphics 640,480 Local Text:String = "No key pressed yet" While Not KeyHit(KEY_ESCAPE) If PollEvent() If CurrentEvent.ID = EVENT_KEYDOWN Text = "Key "+CurrentEvent.Data+" Pressed" End If If CurrentEvent.ID = EVENT_KEYUP Text = "Key "+CurrentEvent.Data+ " Released" End If End If Cls DrawText text,10,10 Flip Wend |
| ||
| oops Last edited 2011 |