You use what is called a
flag. A flag is most commonly a boolean variable, in other words, its value is either TRUE or FALSE.
The flag is down.
flag = 0
The flag is up.
flag = 1
If scancode(18) = 1 and flag = 0
inc var, 1
rem was the button pressed? YES, so throw up the flag to signal that
flag = 1
endif
rem if the button is not being pressed, put the flag down.
if scandode(18) <> 18 then flag = 0
What this means is, if the flag is up, it signals that the operation is currently taking place. In this example, a button being pressed. When the button is released, the flag stops signalling, saying that the button has not yet been pressed.
"eureka" - Archimedes