; FlushKeys Example ; ----------------- Graphics 640,480,0,2 SetBuffer BackBuffer() ; Keypresses queue up in a buffer until your program reads them. ; FlushKeys empties that queue - call it before a "press a key" ; prompt so an old, stale keypress cannot skip it. flush_mode=1 quit=0 Repeat ; Start each round with an empty queue FlushKeys ; Phase 1: let keypresses pile up unread for three seconds finish=MilliSecs()+3000 While MilliSecs()0 If k>=32 And k<=126 Then caught$=caught$+Chr$(k) k=GetKey() Wend ; Discard Space/F presses made while mashing so the menu below ; does not trigger instantly dummy=KeyHit(57)+KeyHit(33) ; Phase 3: show the result and offer another run done=0 While done=0 Cls Text 0,0,"Space: run again F: toggle FlushKeys Esc: exit" Text 0,40,"Keys read from the buffer: '"+caught$+"'" If used_flush Then Text 0,60,"FlushKeys was called first, so the queue came back empty." Else Text 0,60,"No flush - every buffered press was still waiting." End If If flush_mode Then Text 0,100,"Next run: FlushKeys ON" Else Text 0,100,"Next run: FlushKeys OFF" End If Flip If KeyHit(57) Then done=1 If KeyHit(33) Then flush_mode=1-flush_mode If KeyDown(1) Then quit=1 If quit Then done=1 Wend Until quit End