无法使用autohotkey单击窗口中的按钮

时间:2015-07-07 15:22:48

标签: autohotkey

我是AHK的新手,并试图模拟窗口上的按钮点击。 我想点击"接受"启动窗口的按钮。但它不起作用。下面是窗口的WinSpy。 窗口是这样的: - enter image description here

对照" TcxButton2"在ClassNN中突出显示。

我尝试了以下

^j::
;Run, KBDiag.exe , C:\Program Files\Knorr-Bremse\KB Diag
If WinExist "AHK_class TformSplash"
{
    ;WinActivate
    ;PostMessage does not work too
    ;PostMessage, 0x201, , , TcxButton2, Accept ; 0x201 is WM_LBUTTONDOWN
    ;PostMessage, 0x202, , , TcxButton2, Accept ; 0x202 is WM_LBUTTONUP
    ;
    WinActivate
    ControlFocus , TcxButton2, Knorr-Bremse SfN,, , 
    ControlClick , TcxButton2, Knorr-Bremse SfN,, , 
    MsgBox %ErrorLevel%  ; ErrorLevel is '1' , hence something was not okay


}

Return

请参阅下面的启动窗口的屏幕截图 enter image description here

我不知道我做错了什么。 帮助赞赏!

1 个答案:

答案 0 :(得分:0)

好的,我设法解决了这个问题。 如果要匹配的字符串可以出现在窗口的任何位置,则必须将属性SetTitleMatchMode设置为“2”。

如AHK帮助文件中所示: -

  SetTitleMatchMode, MatchMode

  2: A window's title can contain WinTitle anywhere inside it to be a match. 

这里的工作代码: -

    SetTitleMatchMode, 2
    ControlSendButton = TcxButton2
    ControlFocus , %ControlSendButton%, ,Knorr-Bremse SfN, ,
    ; Also the string is not present in WinTitle, hence the string is matched against WinText now
    ControlClick , %ControlSendButton%, ,Knorr-Bremse SfN, ,