Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Autohotkey 自动热键选择弹出窗口不工作_Autohotkey - Fatal编程技术网

Autohotkey 自动热键选择弹出窗口不工作

Autohotkey 自动热键选择弹出窗口不工作,autohotkey,Autohotkey,我编写了一个脚本来测试选择弹出窗口 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

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

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
块工作正常。但是,send
if
块有时有效,有时无效。活动窗口信息显示弹出窗口的类信息为:

窗口标题、类和进程

Question
ahk_class #32770
ahk_exe Rgui.exe


我不知道为什么
IfWinExist,%popWin%
不起作用。我尝试将
popWin:=“ahk#u class#32770 ahk#u exe Rgui.exe”
更改为
popWin:=“ahk#u class#32770”
,但它有时有效,有时无效。那么,我应该怎么做才能正确选择弹出窗口呢?

我已经更改了您的自动热键代码,这样它就可以为您提供所需的功能

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检查会在窗口存在之前进行,因此不会找到窗口。

我已经更改了自动热键代码,这样,它应该为您提供所需的功能

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检查将在窗口存在之前进行,因此将找不到窗口