This is a very simple, yet extremely helpful function to have on any project.
What it does:
Every call, it will see if you have just pressed a key to send only once and the general keystate.
Instead of doing this every time you want a key to only do something once (like toggle a debug window or fire a weapon)
If Keystate(28) = 1
If PressedKey = 0
PressedKey = 1
`Do stuff
Endif
Else
PressedKey = 0
Endif
Now you only need to call this:
If KeyS(28,1) = 1
`Do stuff
Endif
Since I needed a lot of toggle buttons, I find myself using this for every time I use Keystate.
The second parameter is: 0 for general keystate, 1 will =1 only the first loop the key is pressed.
Heres the code:
<<<<<>>>>>
` Use KeyS(x,0) for regular keystate.
` Use KeyS(x,1) for one loop of keypress.
` Meaning if I press the 'w' key, that value will only pass
` as true ONCE, and can only reset once the key is pressed
` again. So if I press 'w' for 30 minutes, only that first loop
` will show as true, then the rest will show as false.
DIM KeyS(88,1)
Function UpdateKeystate()
For x = 1 to 88
If Keystate(x)=1
If KeyS(x,0)=0
KeyS(x,1)=1
KeyS(x,0)=1
else
KeyS(x,1)=0
Endif
else
KeyS(x,0)=0
Endif
Next x
Endfunction
<<<<<>>>>>
Ventures of the worlds around us are limited only by our imagination.