You can interpret your question as 2 things;
- either count the number of times a key has been pressed
- or check for a double press.
keycounter:
sync on : sync rate 0
do
cls
set cursor 0,0
print keycounter
`prevent the code from infinitly counting your keypress
if keylock = 0
keycounter = keycounter + spacekey()
endif
`store the state of the spacekey in a variable so we can check it in the next loop
keylock = spacekey()
sync
loop
`keylock = 0 and spacekey() = 0 : the spacebar hasn't been touched recently.
`keylock = 0 and spacekey() = 1 : the spacebar has been pressed this loop, but not the previous.
`keylock = 1 and spacekey() = 1 : the spacebar has been pressed and held of atleast 1 loop.
`keylock = 1 and spacekey() = 0 : the spacebar has been released this loop, but not the previous.
`(note: only works if you check before the 'keylock = spacekey()' line)
check for doublepress:
sync on : sync rate 0
do
cls
set cursor 0,0
print "doublepress: ",doublepress
print "keylock: ",keylock
print "timer: ",time - timer()
`if the spacebar is pressed AND the timer is running AND the spacebar has not been pressed in the previous loop
if spacekey() = 1 and time > timer() and keylock = 0
doublepress = 1
endif
`if the timer runs out, doublepress will be 0
if time =< timer()
doublepress = 0
endif
`store the state of the spacebar in a variable so we can use that in the next loop
`lower the timer value to increase the speed you have to 'repress' the spacebar
if spacekey() = 1
keylock = 1
time = timer() + 500
endif
if spacekey() = 0
keylock = 0
endif
sync
loop