函数参考


GUIGetCursorInfo

获取(相对于 GUI 窗口的)鼠标位置.

GUIGetCursorInfo ( [窗口句柄] )

参数

窗口句柄 [可选参数] 目标窗口句柄.若此参数缺省则使用"当前"窗口.

返回值

成功: 返回一个5个元素的数组来表示鼠标的坐标信息:
$array[0] = X 坐标(水平轴)
$array[1] = Y 坐标(垂直轴)
$array[2] = 鼠标左键被按下 (1 为按下, 0 为未按下)
$array[3] = 鼠标右键被按下 (1 未按下, 0 为未按下)
$array[4] = 鼠标下面的控件的控件ID( 0 为没有或者无法获取)
失败: 返回 0 并设置 @error 为 1

注意/说明

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.

相关

GUICreate, GUIGetMsg

示例/演示


#include <GUIConstantsEx.au3>

Global $x, $y

Example()

Func Example()
    Local $msg

    HotKeySet("{Esc}", "GetPos")

    GUICreate("Press Esc to Get Pos", 400, 400)
    $x = GUICtrlCreateLabel("0", 10, 10, 50)
    $y = GUICtrlCreateLabel("0", 10, 30, 50)
    GUISetState()

    ; Run the GUI until the dialog is closed
    Do
        $msg = GUIGetMsg()
    Until $msg = $GUI_EVENT_CLOSE
EndFunc   ;==>Example

Func GetPos()
    Local $a

    $a = GUIGetCursorInfo()
    GUICtrlSetData($x, $a[0])
    GUICtrlSetData($y, $a[1])
EndFunc   ;==>GetPos