【发布时间】:2016-07-09 13:15:01
【问题描述】:
我刚刚完成了一段代码来完成以下事情。当我在 Firefox 或 EndNote 中通过鼠标进行选择时,脚本会发送 Ctrl+c 并检查剪贴板是否匹配正则表达式。如果匹配,它会更改剪贴板内容并显示工具提示。它适用于这两个程序。 Adobe Acrobat 有时会在发送 Ctrl+c 时显示错误(即使用户按下 ctrl-c Acrobat 有时也会显示著名的“复制到剪贴板时出错。发生内部错误)。因此它决定分配一个F9 热键,但它适用于所有程序,而不仅仅是 Acrobat。如何为一个窗口分配热键 - Acrobat?这是我的代码。我知道它很蹩脚 - 我是一般编程的新手,在 AHK 中特别的。
#If WinActive("ahk_exe firefox.exe") || WinActive("ahk_exe EndNote.exe") || WinActive("ahk_exe Acrobat.exe")
if WinActive("ahk_exe Acrobat.exe")
F9::
{
Clipboard:=""
send,^c
ClipWait, 1
ToolTip % Clipboard := RegExReplace(Clipboard, "\r\n", " ")
SetTimer, ToolTipOff, -1000
}
return
~LButton::
now := A_TickCount
while GetKeyState("LButton", "P")
continue
if (A_TickCount-now > 500 )
{
Send ^c
if WinActive("ahk_exe firefox.exe")
{
If RegExMatch(Clipboard, "[0-9]\.\s[A-Za-z,]*\s[A-Za-z]*")
{
regex := "[0-9]\.\s*|\s?\([^)]*\)|\."
replace := ""
}
else If RegExMatch(Clipboard,"[0-9]{2}[-\/][0-9]{2}[-\/][0-9]{4}")
{
Clipboard := RegExReplace(Clipboard, "^0", "")
regex := "\/"
replace := "."
}
else return
}
else if WinActive("ahk_exe EndNote.exe")
{
If RegExMatch(Clipboard, "[a-z]+\,\s[A-Z0-9‘“]")
{
regex := "\??!?\:|\?|!"
replace := "."
}
else return
}
ToolTip % Clipboard := RegExReplace(Clipboard, regex, replace)
SetTimer, ToolTipOff, -1000
}
return
#If
ToolTipOff:
ToolTip
return
【问题讨论】:
标签: autohotkey