I was learning about keycode detection and discovered that the way it is being used in this code snippet causes unexpected behavior.
Of course I will avoid using keycodes in this way but was curious as to why it works badly.
Strict Graphics 640,480 HideMouse Repeat Cls If KeyHit(key_return)=False DrawText "Return key for action -",100,240 DrawText "Escape key to exit.",100,255 If KeyHit(key_return) '<- This works after a few taps but KeyDown(key_return) works very well. Cls SetColor 0,255,0 DrawText "Return Key hit, now going to TheLoop().",100,240 Flip Delay 1700 TheLoop() EndIf EndIf Flip Until KeyHit(key_escape) Function TheLoop() Local x, x1 Repeat For x=30 To 200 If KeyHit(key_space) Return Cls SetColor -x,-x,255 DrawOval x,x,x,x SetColor 255,255,255 DrawText"Hit space key to get back to main loop",x,x+x Flip Next For x1=x To 30 Step-3 If KeyHit(key_space) Return Cls SetColor 255,-x1,-x1 DrawOval x1,x1,x1,x1 SetColor 255,255,255 DrawText"Hit space key to get back to main loop",x1,x1+x1 Flip Next Until KeyHit(key_space) End Function
Of course I will avoid using keycodes in this way but was curious as to why it works badly.