Getkey does not store the last key pressed.
In this thread, Khoraski and I came to the false conclusion that Getkey does not return to zero after a key is pressed. This is false. I discovered that because I did this small test program:
While 1 ClrText Locate 1,1,Getkey WhileEnd
Try pressing any key. You will notice that it will show the value of the key only while the key is being pressed. The reason that I thought that it was not returning to zero afterwards was because my program was setup like this:
"Test"? -> V While not Getkey WhileEnd "Done"
It would go straight to "Done" without looping. I have discovered why that is. When you finish inputting in the test prompt, you press EXE. You do not release the EXE key immediately, though. So Getkey is true and breaks from the loop. How do we fix this?
Deprecated. See the edit below.
"Test"? -> V //begin delay 2 -> I While I>0 I-1 -> I WhileEnd //end delay While not Getkey WhileEnd "Done"
If you have any more problems with this function, feel free to post here so I can help figure out whats going on.
cfxm provided a very good piece of code that works better than my delay.
"TEST"? -> V While Getkey WhileEnd Do Getkey LpWhile Not Ans // Or any specific key
The first loop waits for you to release the key, and the second waits for you to press a new one.
3298 provided this useful code for checking if a key was pressed. However, the original author was someone else.
While 1 Do Getkey -> K LpWhile K=0 If K=27 Then ... IfEnd While Getkey=K WhileEnd WhileEnd
The Do-LpWhile loop waits for a key and stores it in K, the While loop at the end waits until the key is released.