AHK:每当弹出窗口时关闭一个窗口

时间:2016-03-25 00:40:32

标签: autohotkey

我写了一个AHK脚本,用于在按F9时从Adobe Acrobat复制文本。然后根据正则表达式更改它,并在工具提示中显示复制的文本。另外,我添加了代码来自动关闭Acrobat有时在处理文本时显示的恼人窗口,臭名昭着There was an error while copying to Clipboard. An internal error occurred.当此窗口没有显示时,脚本会一直显示工具提示,该工具提示旨在关闭经过一段特定的时间。我一直在撞墙,但我不知道如何解决这个问题。

;#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

1 个答案:

答案 0 :(得分: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 会导致子程序(Label)以指定的时间间隔自动重复启动。

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

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

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