; KeyHit Example ; -------------- Graphics 640,480,0,2 SetBuffer BackBuffer() ; Load the player ship sprite ship=LoadImage("media/player.bmp") ; One entry per bullet in flight Type bullet Field x,y End Type ang#=0 shots=0 While Not KeyDown(1) Cls ; The ship patrols by itself so there is always motion on screen ang=ang+2 x=320+Sin(ang)*250 ; KeyHit returns how many times the key was PRESSED since the ; last call - holding Space down fires only ONE bullet per press. ; (Compare KeyDown, which stays 1 for as long as the key is held.) hits=KeyHit(57) ; 57 = Space (see the ScanCodes help page) If hits>0 Then b.bullet=New bullet b\x=x b\y=400 shots=shots+hits End If ; Move and draw the bullets For b.bullet=Each bullet b\y=b\y-8 If b\y<-8 Then Delete b Else Rect b\x-1,b\y,3,8,True End If Next DrawImage ship,x-16,404 Text 0,0,"Space: fire (tap it - holding does not autofire) Esc: exit" Text 0,20,"KeyHit(57) presses counted so far: "+shots Flip Wend End