【问题标题】:AutoHotKey select pop-up window not workAutoHotKey 选择弹出窗口不起作用
【发布时间】:2017-01-05 12:08:46
【问题描述】:

我编写了一个脚本来测试选择弹出窗口。

SetTitleMatchMode, 2

winTitle:="RGui (64-bit) ahk_class Rgui Workspace ahk_exe Rgui.exe"
popWin:="ahk_class #32770 ahk_exe Rgui.exe"
IfWinExist,%winTitle%
{
    WinActivate
    send !{F4}
}

IfWinExist,%popWin%
{
    WinActivate
    WinWaitActive, %popWin%
    WinGetClass, outputvar, %popWin%
    MsgBox %outputvar%
}

此脚本旨在发送 ALT-F4 以关闭打开的 R 窗口,并在出现确认弹出窗口时显示弹出窗口的类名。

第一个 if 块工作正常。但是,发送if 块有时有效,有时无效。活动窗口信息显示弹出窗口的类信息是:

窗口标题、类和进程

Question
ahk_class #32770
ahk_exe Rgui.exe

snapshot of the above info

我不知道为什么IfWinExist,%popWin% 不起作用。我尝试将popWin:="ahk_class #32770 ahk_exe Rgui.exe" 更改为popWin:="ahk_class #32770",但有时它仍然有效,有时无效。那么如何正确选择弹窗呢?

【问题讨论】:

    标签: autohotkey


    【解决方案1】:

    我已经更改了您的 AutoHotkey 代码,以便它可以为您提供所需的功能。

    SetTitleMatchMode, 2
    
    winTitle:="RGui (64-bit) ahk_class Rgui Workspace ahk_exe Rgui.exe"
    popWin:="ahk_class #32770 ahk_exe Rgui.exe"
    
    if (hWnd := WinExist(winTitle)) ;this assigns hWnd, it does not compare hWnd with WinExist(winTitle)
    {
        ;WinActivate, ahk_id %hWnd%
        ;send !{F4}
        WinClose, ahk_id %hWnd% ;WinClose is more direct than Alt+F4 if it works (Send can potentially send key presses to the wrong window if a new window suddenly appears)
    }
    
    WinWait, %popWin%, , 5 ;wait for window to exist, give up after 5 seconds
    if !ErrorLevel ;if window found within 5 seconds
    {
        WinGet, hWnd, ID, %popWin%
        WinActivate, ahk_id %hWnd%
        WinGetClass, outputvar, ahk_id %hWnd%
        MsgBox %outputvar%
    }
    

    注意: 在大多数情况下,WinActivate 需要指定窗口标题/hWnd。

    您的代码的第二部分有时有效,但有时无效,可能是因为如果弹出窗口出现得很快,那么 IfWinExist 会找到窗口,但如果弹出窗口出现得很慢,则在窗口存在之前会发生 IfWinExist 检查,因此将找不到窗口。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多