WaitMouse ( )
Parameters
| None. |
Description
|
Halts the program until a mouse button is clicked, then returns which one. It is the mouse version of WaitKey: a "click to continue" pause for a title card, an end-of-level screen or a quick tool. The value it returns is the button number - 1 left, 2 right, 3 middle - so you can offer a simple choice on the screen and act on which button the player used. The gotcha is that it blocks completely. Your loop stops, nothing animates, and anything you drew on the back buffer is still invisible, so draw the screen and Flip it before you call WaitMouse. It polls about fifty times a second and keeps the window responsive while it waits, and if the player closes the window instead of clicking, the program ends there. A click that was already queued before the call satisfies it immediately, which is how "the pause screen flashed past" happens - call FlushMouse first if you want the wait always to be a fresh click. Inside a running game use MouseHit in your main loop instead, so animation, timers and music keep going while you wait for the player. MouseWait is the same command under an older name. See also: MouseWait, MouseHit, GetMouse, FlushMouse, WaitKey. |
Example
; WaitMouse Example ; ----------------- Graphics 640,480,0,2 SetBuffer BackBuffer() last_btn=0 Repeat ; Draw the frame BEFORE blocking so the prompt is readable while ; the program is halted inside WaitMouse. Cls Text 320,160,"WaitMouse halts the program until a button is pressed",True If last_btn>0 Then Text 320,200,"Last button code: "+last_btn+" (1=left, 2=right, 3=middle)",True Text 320,240,"Press a mouse button (right button: exit)",True Flip ; WaitMouse blocks here and returns the pressed button's code last_btn=WaitMouse() Until last_btn=2 End
Index