【问题标题】:AHK: closing a window whenever it pops upAHK:每当它弹出时关闭一个窗口
【发布时间】:2016-03-25 15:23:10
【问题描述】:

我编写了一个 AHK 脚本,用于在按 F9 时从 Adob​​e 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

【问题讨论】:

  • 请澄清期望的行为和问题所在。脚本中间CheckForMsgBox的作用是什么?

标签: autohotkey


【解决方案1】:
;#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

【讨论】:

  • 效果很好。非常感谢您的回答和评论!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-29
  • 2019-04-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多