AHK:每当弹出窗口时就将其关闭

问题描述 投票:0回答:2

我编写了一个 AHK 脚本,旨在在按 F9 时从 Adobe Acrobat 复制文本。然后它根据正则表达式更改它并在工具提示中显示复制的文本。此外,我还添加了代码来自动关闭 Acrobat 在处理文本时有时会显示的烦人窗口,即臭名昭著的 复制到剪贴板时出错。发生内部错误。 当此窗口未显示时,脚本会不断显示工具提示,该提示旨在在指定时间后关闭。我一直用头撞墙,但我不知道如何纠正这个问题。

;#NoTrayIcon
#Persistent
#SingleInstance
F9::
#If WinActive("ahk_exe Acrobat.exe")
{
Clipboard:=""
send,^c
ClipWait, 1
Clipboard := RegExReplace(Clipboard, "\r\n", " ")
SetTimer,CheckForMsgBox,100
CheckForMsgBox:
    IfWinExist, Adobe Acrobat
    {
        Send {Enter}
        SetTimer,CheckForMsgBox,Off
    }
;Return
If (StrLen(Clipboard) < 120)
ToolTip % Clipboard
Else
ToolTip Copied
SetTimer, ToolTipOff, -1000
return
}
#If

ToolTipOff:
ToolTip
return
autohotkey
2个回答
2
投票
;#NoTrayIcon
; #Persistent ; (1)
#SingleInstance
SetTimer,CheckForMsgBox,100 ; (2)
return

#If WinActive("ahk_exe Acrobat.exe") ; (3)

F9::    
clipboard:=""
send,^c
ClipWait, 1
Clipboard := RegExReplace(Clipboard, "\r\n", " ")
If (StrLen(Clipboard) < 120)
    ToolTip %Clipboard%
Else
    ToolTip Copied
SetTimer, ToolTipOff, -1000
return

#If  ; turn off context sensitivity

ToolTipOff:
ToolTip
return

CheckForMsgBox:
; ControlSend, Control, Keys, WinTitle, WinText, ExcludeTitle, ExcludeText
ControlSend, , {Enter}, Adobe Acrobat  ; Close this unwanted window whenever it appears
return

(1) 包含热键、热字符串或任何 OnMessage() 或 Gui 的使用的脚本会自动保持持久性

(2) SetTimer 使子程序(标签)以指定的时间间隔自动重复启动。

https://autohotkey.com/docs/commands/SetTimer.htm

(3) 与 #IfWin 指令一样,#If 是位置性的:它会影响脚本中下方的所有热键和热字串。

https://autohotkey.com/docs/commands/_If.htm


0
投票

您可以创建一个单独的脚本,仅等待并关闭复制剪贴板错误窗口。

Loop
{
    WinWait, Adobe Acrobat ahk_class CLASS ahk_exe EXE
    WinClose, Adobe Acrobat ahk_class CLASS ahk_exe EXE
}

CLASSEXE 替换为可以通过 Window Spy.ahk 获取的错误窗口类和 exe。

© www.soinside.com 2019 - 2024. All rights reserved.