FlushMouse
Parameters
| None. |
Description
|
Throws away pending mouse clicks so old input cannot leak into the next screen. Every click is recorded twice: as a count that MouseHit hands out, and as an entry in the queue that GetMouse reads. FlushMouse clears both for all three buttons in one call. Use it whenever the game changes context. A player clicking rapidly to finish a fight should not instantly dismiss the results screen that follows, and clicks made during a long load should not press the first button of the menu that appears. A flush just before you show the new screen keeps that from happening. It is also the fix for a pause that flashes past: WaitMouse is satisfied by a click that was already queued, so flush first if you want the wait to need a fresh one. What it does not do is release buttons the player is physically still holding - MouseDown reads the live state and carries on returning 1 until they let go. It also leaves the pointer position and the wheel count alone. See also: MouseHit, GetMouse, MouseDown, WaitMouse, FlushKeys, FlushJoy. |
Example
; FlushMouse Example ; ------------------ Graphics 640,480,0,2 SetBuffer BackBuffer() ; Mouse clicks queue up until your program reads them. FlushMouse ; empties that queue - call it before a "click to continue" prompt ; so a stale click cannot skip it. flush_mode=1 quit=0 Repeat ; Start each round with an empty click queue FlushMouse ; Phase 1: click wildly - the clicks stay queued because nothing ; reads MouseHit during the countdown finish=MilliSecs()+3000 While MilliSecs()<finish If KeyDown(1) Then Exit Cls Text 0,0,"Click the mouse buttons NOW - the clicks are queuing up!" Text 0,20,"Time left: "+((finish-MilliSecs())/1000+1) If flush_mode Then Text 0,40,"FlushMouse WILL be called before the queue is read." Else Text 0,40,"FlushMouse will NOT be called - watch the clicks survive." End If Flip Wend ; Phase 2: optionally flush, then read the queued click counts used_flush=flush_mode If flush_mode Then FlushMouse ; the documented command - empties the queue clicks=MouseHit(1)+MouseHit(2)+MouseHit(3) ; Phase 3: show the result and offer another run done=0 While done=0 Cls Text 0,0,"Space: run again F: toggle FlushMouse Esc: exit" Text 0,40,"Queued clicks read after the countdown: "+clicks If used_flush Then Text 0,60,"FlushMouse was called first, so the queue came back empty." Else Text 0,60,"No flush - every buffered click was still counted." End If If flush_mode Then Text 0,100,"Next run: FlushMouse ON" Else Text 0,100,"Next run: FlushMouse 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
Index