Key repeat?
Blitz3D Forums/Blitz3D Beginners Area/Key repeat?
| ||
I am looking for a way to get the status of a single key on the keyboard. I want to be able to press p to pause the game and p again to un-pause the game or have the up arrow make we walk until I press it again. I have searched and have not found away to reuse the key for another purpose. If you can help in anyway that would be great. I am very new to programming and I am a bit overwhelmed. Thank you |
| ||
Look up Keyhit and Flushkeys. A quick and dirty example.. If Keyhit( 25 ) ;Display Pause Information Flushkeys() repeat : until keyhit( 25 ) Endif |
| ||
For what you're trying to do there, the best approach might be to use a variable as a toggle. [bbcode]toggle = False While Not KeyHit( 1 ) ; Exit the program if the ESCAPE key is pressed. If KeyHit( 57 ) ; Press the SPACEBAR to toggle the variable's state. toggle = Not toggle ; Invert the boolean (True/False) state of the variable. EndIf If toggle ; Print some text depending on the state of the 'toggle' variable. Print "Toggle: On" Else Print "Toggle: Off" EndIf Delay( 20 ) ; This is just here to give the OS room to breath. Wend End[/bbcode] |
| ||
Thank you Zethrax your code worked great. |
| ||
and do a loop for freeze the program. |