Function Reference


GUIGetCursorInfo

Gets the mouse cursor position relative to GUI window.

GUIGetCursorInfo ( [winhandle] )

Parameters

winhandle [optional] The handle of the window to use. If omitted the "current" window will be used.

Return Value

Success: a five-element array that containing the mouse cursor information:
    $aArray[0] = X coord (horizontal)
    $aArray[1] = Y coord (vertical)
    $aArray[2] = Primary down (1 if pressed, 0 if not pressed)
    $aArray[3] = Secondary down (1 if pressed, 0 if not pressed)
    $aArray[4] = ID of the control that the mouse cursor is hovering over (or 0 if none)
Failure: sets the @error flag to non-zero.

Remarks

The coordinates given are relative to the GUI window (known as client coords).

If the "winhandle" parameter is used then the specified window becomes the new "current" window.

The mouse cursor position is successful only on an window created by a GUICreate(). When no winhandle it will be successful if the GUI Windows is active.

ListViewItem or TreeViewItem controlID will never be returned, only the parent Listview or TreeView control ID is.

Related

GUICreate, GUIGetMsg

Example

#include <GUIConstantsEx.au3>

Global $g_idX = 0, $g_idY = 0

Example()

Func Example()
        HotKeySet("{ESC}", "GetPos")

        GUICreate("Press Esc to Get Pos", 400, 400)
        $g_idX = GUICtrlCreateLabel("0", 10, 10, 50)
        $g_idY = GUICtrlCreateLabel("0", 10, 30, 50)
        GUISetState(@SW_SHOW)

        ; Loop until the user exits.
        While 1
                Switch GUIGetMsg()
                        Case $GUI_EVENT_CLOSE
                                ExitLoop

                EndSwitch
        WEnd

        GUIDelete()
EndFunc   ;==>Example

Func GetPos()
        Local $a = GUIGetCursorInfo()
        GUICtrlSetData($g_idX, $a[0])
        GUICtrlSetData($g_idY, $a[1])
EndFunc   ;==>GetPos