GETMOUSE


Retrieves the status of the mouse pointing device

Syntax:
declare function Getmouse ( byref x as long, byref y as long, byref wheel as long = 0, byref buttons as long = 0, byref clip as long = 0 ) as long
declare function Getmouse ( byref x as longint, byref y as longint, byref wheel as longint = 0, byref buttons as longint = 0, byref clip as longint = 0 ) as long

Usage:
result = Getmouse (x, y [, [ wheel ] [, [ buttons ] [, [ clip ]]]])

Parameters:
x
x coordinate value
y
y coordinate value
wheel
scroll wheel value
buttons
button status
clip
clip status

Return Value:
0 on success, or 1 on error (for example because the mouse is outside the graphic window) or on failure. (sets a runtime error)

Description:
Getmouse retrieves the mouse position and buttons status; information is returned in the variables passed to this function by reference. If a mouse is not available, all variables will contain the -1 value.

If in console mode, the x and y coordinates are the character cell coordinates the mouse is currently on; the upper left corner of the screen is at coordinates 0, 0. If the mouse moves out of the console window, Getmouse returns the last coordinate on the window that the mouse was on. If in console mode and fullscreen, the scroll wheel value is not returned.

If in graphics mode, x and y will always be returned in pixel coordinates still relative to the upper left corner of the screen, which is at 0,0 in this case; custom coordinates system set via View or Window do not affect the coordinates returned by Getmouse.
If the mouse runs off the graphic window, all values are set to -1 and the return value of the function is set to 1. This may result in misinterpretation for the buttons and wheel if the return value of the function is not also tested.

Wheel is the mouse wheel counter; rotating the wheel away from you makes the count to increase, rotating the wheel toward you makes it to decrease. At program startup or when a new graphics mode is set via Screen (Graphics), wheel position is reset to 0. FreeBASIC may not always support mouse wheels for a given platform, in which case 0 is always returned.

Buttons stores the buttons status as a bitmask: bit 0 is set if left mouse button is down; bit 1 is set if right mouse button is down; bit 2 is set if middle mouse button / wheel is down.

Clip stores the mouse clipping status; if 1, the mouse is currently clipped to the graphics window; if 0, the mouse is not clipped.

The error code returned by Getmouse can be checked using Err in the next line. The function version of Getmouse returns directly the error code as a 32 bit Long.

Warning: When the flag GFX_SHAPED_WINDOW is set (see Screenres), Getmouse is only active in any colored area, ie there where color <> RGBA(255, 0, 255, alpha).

Examples:
Dim As Long x, y, buttons, res
' Set video mode and enter loop
ScreenRes 640, 480, 8
Do
    ' Get mouse x, y and buttons. Discard wheel position.
    res = GetMouse (x, y, , buttons)
    Locate 1, 1
    If res <> 0 Then '' Failure

#IFDEF __FB_DOS__
        Print "Mouse or mouse driver not available"
#ELSE
        Print "Mouse not available or not on window"
#ENDIF

    Else
        Print Using "Mouse position: ###:###  Buttons: "; x; y;
        If buttons And 1 Then Print "L";
        If buttons And 2 Then Print "R";
        If buttons And 4 Then Print "M";
        Print "   "
    End If
Loop While Inkey = ""
End

'Example 2: type-union-type structure
Type mouse
    As Long res
    As Long x, y, wheel, clip
    Union
        buttons As Long
        Type
            Left:1 As Long
            Right:1 As Long
            middle:1 As Long
        End Type
    End Union
End Type
 
Screen 11
Dim As mouse m

Do
    m.res = GetMouse( m.x, m.y, m.wheel, m.buttons, m.clip )
    ScreenLock
    Cls
    Print Using "res = #"; m.res
    Print Using "x = ###; y = ###; wheel = +###; clip = ##"; m.x; m.y; m.wheel; m.clip
    Print Using "buttons = ##; left = #; middle = #; right = #"; m.buttons; m.Left; m.middle; m.Right
    ScreenUnlock
    Sleep 10, 1
Loop While Inkey = ""

Dialect Differences:
Platform Differences:
Differences from QB:
See also:
Back to User Input Functions
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki



sf.net phatcode