0

我知道实际按钮的手柄。我想检查是否单击了该按钮,如果是,则会触发自动热键脚本。

提前致谢!

4

2 回答 2

0

您是否尝试过使用 ImgSearch 来“动态”找到按钮的 XY 坐标,然后执行 if (MouseX => ImageX and MouseX =< ImageX + ImageWidth)?

伪代码(未测试):

Settimer, FindButton, 1000
Settitlematchmode, 2
Return

FindButton:
IfWinActive, YourAppWindowTitle
    ImageSearch, ImageX, ImageY, 0, 0, A_ScreenWidth, A_ScreenHeight, C:\ButtonImage.bmp
Return

#IfWinActive, YourAppWindowTitle
~LButton::
MouseGetPos, MouseX, MouseY
if (MouseX => ImageX and MouseX =< ImageX + ImageWidth)
{
    if (MouseY => ImageY and MouseY =< ImageY + ImageHeight)
    {
        Run your code here
    }
}
Return
#IfWinActive
于 2013-02-28T07:52:41.453 回答
0

你说的对。您可以使用它来代替 ImgSearch。

ControlGetPos, x, y, w, h, button1, ahk_class CalcFrame
MsgBox, %x% %y% %w% %h%
return

因此,您必须在每次鼠标单击后运行 ControlGetPos(仅当目标窗口标题处于活动状态时),然后将实际鼠标坐标与按钮单击区域进行比较。

这是计算器的一些代码:

#SingleInstance Force
#Persistent

#IfWinActive, ahk_class CalcFrame
    ~LButton::
    MouseGetPos, MouseX, MouseY
    ControlGetPos, ButtonX, ButtonY, ButtonW, ButtonH, button1, ahk_class CalcFrame
    ButtonX2:=ButtonX + ButtonW
    ButtonY2:=ButtonY + ButtonH
    if MouseX between %ButtonX% and %ButtonX2%
    {
        if MouseY between %ButtonY% and %ButtonY2%
        {
            MsgBox, You pressed the MC button
        }
    }
    Return
#IfWinActive
于 2013-02-28T12:36:16.133 回答