Blitz3D+ Command Reference

GetMouse ( )

Parameters

None.

Description

Takes the next mouse click out of the queue and returns which button it was.

Unlike MouseDown and MouseHit you do not tell it which button to look for. It hands back 1 for left, 2 for right and 3 for middle, or 0 when no click is waiting. That makes it a neat fit for a Select/Case block that handles all three buttons in one place, and for click handling that lives in a single routine rather than being spread over several button tests.

Clicks are queued in the order they happened, and each call removes one. Drain the queue each frame with a loop that keeps calling GetMouse until it returns 0, and no click is ever missed even if the player got two in before your next frame.

It reports button presses only. It does not tell you where the pointer was - read MouseX and MouseY in the same frame for that - and it does not fire again while a button is simply held down. FlushMouse empties the queue.

See also: MouseHit, MouseDown, WaitMouse, FlushMouse, MouseX, GetKey.

Example

; GetMouse Example
; ----------------

Graphics 640,480,0,2
SetBuffer BackBuffer()

; Hide the Windows pointer - the example draws its own crosshair
HidePointer

last_btn=0

While Not KeyDown(1)

    Cls
    mx=MouseX()
    my=MouseY()

    ; GetMouse polls ALL the mouse buttons at once and returns the
    ; number of the one pressed (0 if none) - no need to test each
    ; button separately as with MouseDown/MouseHit.
    b=GetMouse()
    If b>0 Then last_btn=b

    ; Name the last button with Select/Case, as the docs suggest
    Select last_btn
        Case 1
            name$="Left"
        Case 2
            name$="Right"
        Case 3
            name$="Middle"
        Default
            name$="(none yet)"
    End Select

    ; Crosshair so there is something to aim while clicking
    Color 255,255,0
    Oval mx-10,my-10,20,20,False
    Line mx-14,my,mx+14,my
    Line mx,my-14,mx,my+14

    Color 255,255,255
    Text 0,0,"Click any mouse button   Esc: exit"
    Text 0,20,"GetMouse() now: "+b+"   last button: "+last_btn+" "+name$

    Flip

Wend

End

Index