2013-02-28 93 views

回答

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 
+0

這正是我之後的事情,非常感謝! – Ismo 2013-03-01 07:54:53

+0

不客氣! – 2013-03-01 08:07:29

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 
+0

這實際上不是一個壞主意。不過,我寧願使用該按鈕的句柄ID,因爲它更安全,不依賴座標(可能會在其他PC上更改)。 – Ismo 2013-02-28 08:57:27

+0

我明白,這可能值得尋找ID解決方案。我厭倦了用定時器「移動」按鈕(不同的屏幕,移動到屏幕上的窗口等)來解決問題。 – 2013-02-28 11:36:48