..Flushkeys..

BlitzMax Forums/BlitzMax Programming/..Flushkeys..

Naughty Alien(Posted 2010) [#1]
..im just wondering, is there a way to perform sort of FlushKeys() command but only for specific character ?


Tommo(Posted 2010) [#2]
Function flushOneKey(keycode%)
	KeyHit(keycode)
	EmitEvent (CreateEvent(EVENT_KEYUP,, keycode))
End Function



matibee(Posted 2010) [#3]
Just calling the Key_hit function for the specific key was enough for me...

This caused the key to be buffered and the jump executed at the next available opportunity (pseudo code)..

if ( not OnGround )
  continuejump()
else 
  if ( keyhit( key_space ) )
     jump()
  end if 
end if 


Whereas, checking the key every update was what I needed to to..
local wantJump:Int = keyhit( key_space )
if ( not OnGround )
  continuejump()
else 
  if ( wantJump )
     jump()
  end if 
end if 



ziggy(Posted 2010) [#4]
I would say:
Function FlushOneKey(keycode:Int)
	While KeyHit(keycode);Wend
End Function



Tommo(Posted 2010) [#5]

While KeyHit(keycode);Wend


KeyHit returns count of hitings from last call of KeyHit/FlushKey, and set counter to 0.
So a While/Wend is not neccesary.