我知道实际按钮的手柄。我想检查是否单击了该按钮,如果是,则触发autohotkey脚本。
提前致谢!
答案 0 :(得分:0)
您是否尝试过使用ImgSearch“动态”找到按钮的XY坐标,然后执行if(MouseX => ImageX和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
答案 1 :(得分: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