Np. It's because of this:
` Wait for the user to let go of the spacebar
repeat
until keystate(57)=0
It stays in the REPEAT/UNTIL loop till you let go of the spacebar.
I have another version that you'll like better. It eliminates that bit of code in the above snip. It's a couple of commands I just noticed in the help files. I don't know when they were added to Darkbasic Pro but it's a nice set of commands that allow us to make any key a toggle switch. It'll do the same thing as a switch in code without the need to create a switch (a switch in programming is either Off (0) or On (1)). To find out all the virtual keys just click on GET KEY STATE() and hit F1 to bring up the help file for that command. In the example code in that help file you'll see all the hex codes for each virtual key.
In this code holding down the spacebar doesn't stop the action:
` Make the background color overwrite text
set text opaque
` Show instructions
print "Hit the spacebar as many times as you can in 5 seconds!"
print "Start hitting the spacebar to begin the count."
` Wait for the user to hit the spacebar (or any key)
wait key
` Set a start time
StartTime=timer()
` Set the starting seconds
StartSecond=5
do
` Calculate the seconds to go
Seconds=StartSecond-((timer()-StartTime)/1000)
` Show the seconds to go
text 0,40,str$(Seconds)+" seconds to go!"
` Show how many hits have happened
text 0,60,"Hits = "+str$(Count)
` Check if the spacebar is hit (toggle is on)
if get key state(0x20)=1
` Increase the counter
inc Count
` Reset the spacebar toggle to off
set key state toggle 0x20,0
endif
` Check if the seconds are up and leave the DO/LOOP
if Seconds=0 then exit
loop
` Show the times up
text 0,80,"Times up!"
text 0,120,"PRESS ENTER TO QUIT"
` Wait for the enter key
repeat
until keystate(28)
To further explain it checks if the spacebar is being hit with GET KEY STATE(0x20)=1 then it increases the counter and resets the spacebar toggle to zero with SET KEY STATE TOGGLE 0x20,0. Without resetting it to zero the spacebar would have to be hit twice to return the toggle to zero (and in that code if SET KEY STATE TOGGLE was remed off it would increase the counter till the spacebar is hit again). I can see many uses for those commands.