Screen scraping 如何检查带有自动热键的窗口上是否存在按钮?

Screen scraping 如何检查带有自动热键的窗口上是否存在按钮?,screen-scraping,autohotkey,Screen Scraping,Autohotkey,在我的例子中,某个按钮有时存在,有时不存在 有没有办法使用自动热键检查窗口上是否存在某个按钮?如果在命令中使用ControlGet,但该控件不存在,则ErrorLevel将设置为1 您可以使用获取控件的窗口句柄(HWND)。如果控件存在,窗口句柄将放在输出变量中并设置为0,否则输出变量将为空,ErrorLevel将为1 在下面的示例中,前两行获取记事本About屏幕上“Ok”按钮的窗口句柄(当然必须显示About屏幕才能工作),并在MsgBox中显示结果。Ok按钮的ClassNN是Button1

在我的例子中,某个按钮有时存在,有时不存在


有没有办法使用自动热键检查窗口上是否存在某个按钮?

如果在命令中使用ControlGet,但该控件不存在,则ErrorLevel将设置为1

您可以使用获取控件的窗口句柄(HWND)。如果控件存在,窗口句柄将放在输出变量中并设置为0,否则输出变量将为空,ErrorLevel将为1

在下面的示例中,前两行获取记事本About屏幕上“Ok”按钮的窗口句柄(当然必须显示About屏幕才能工作),并在MsgBox中显示结果。Ok按钮的ClassNN是Button1

第二行是相同的,但对于不存在Button2的ClassNN控件

ControlGet, Handle, Hwnd,, Button1, About Notepad ahk_class #32770
MsgBox Handle: %Handle%`n`nError: %ErrorLevel%

ControlGet, Handle, Hwnd,, Button2, About Notepad ahk_class #32770
MsgBox Handle: %Handle%`n`nError: %ErrorLevel%

以下是使用以下代码的示例:


你能提供一个具体的例子吗?您想要什么类型的按钮?在什么类型的应用程序中?
; Button1 is the class name for the title bar and close button of the results pane when docked
ControlGet, OutputVar, Visible,, Button1, Notepad++
if ErrorLevel = 0
{
    If OutputVar > 0
    {
        ; Found it docked
        Open := 1
        ; Get the size and coordinates of the title bar and button
        ControlGetPos, X, Y, Width, Height, Button1
        ; Set the coordinates of the close button
        X := Width - 9
        Y := 5
        ; Send a click
        ControlClick, Button1,,,,, NA x%X% y%Y%
    }
}