MouseGetPos

マウスカーソルの現在位置を取得し、オプションでどのウィンドウとコントロールにカーソルを置いているかを取得します。

MouseGetPos &OutputVarX, &OutputVarY, &OutputVarWin, &OutputVarControl, Flag

パラメータ

&OutputVarX, &OutputVarY

型:VarRef

省略したときは、対応する値は保存されません。Otherwise, specify references to the output variables in which to store the X and Y coordinates. The retrieved coordinates are relative to the active window's client area unless CoordMode was used to change to screen coordinates.

&OutputVarWin

型:VarRef

省略したときは、対応する値は保存されません。Otherwise, specify a reference to the output variable in which to store the unique ID number of the window under the mouse cursor. ウィンドウを決定できない場合、この変数は空白になります。

ウィンドウがアクティブでなくても検出されます。隠しウィンドウは検出できません。

&OutputVarControl

型:VarRef

省略したときは、対応する値は保存されません。Otherwise, specify a reference to the output variable in which to store the name (ClassNN) of the control under the mouse cursor. 制御が決定できない場合は、この変数を空白とします。

コントロールの名前は、常にWindow Spyが表示する名前と一致する必要があります。マウスカーソルの下にあるウィンドウがアクティブでなくても、コントロールは検出されます。

Flag

型:整数

If omitted, it defaults to 0, meaning the function uses the default method to determine OutputVarControl and stores the control's ClassNN. Otherwise, specify a combination (sum) of the following numbers:

1: Uses a simpler method to determine OutputVarControl. SysEditやTextPadなどのMDI(Multiple Document Interface)アプリケーションのアクティブ/最上位の子ウィンドウを正しく取得することができるようになりました。ただし、GroupBoxコントロール内のコントロールの検出など、他の目的では精度が落ちます。

2: Stores the control's HWND in OutputVarControl rather than the control's ClassNN.

例えば、両方のオプションを有効にするには、Flagパラメータを3に設定する必要があります。

備考

対応する情報が不要な場合は、出力変数のいずれかを省略することができる。

DPI設定の異なる複数の画面を持つシステムでは、OSのDPIスケーリングにより、返される位置が想定と異なる場合があります。

CoordMode, Win functions, SetDefaultMouseSpeed, Click

マウスカーソルの位置を報告します。

MouseGetPos &xpos, &ypos
MsgBox "The cursor is at X" xpos " Y" ypos

Shows the HWND, class name, title and controls of the window currently under the mouse cursor.

SetTimer WatchCursor, 100

WatchCursor()
{
    MouseGetPos , , &id, &control
    ToolTip
    (
        "ahk_id " id "
        ahk_class " WinGetClass(id) "
        " WinGetTitle(id) "
        Control:" control
    )
}