[英]Autohotkey: Define a hotkey and passthrough it to system dynamically, how to?
我面临一个有点困难的问题。 看看这个脚本:
; Using Autohotkey 1.1.36.2
F2::
send_f2_withcond()
{
if(WinExist("ahk_class Notepad"))
{
ControlSend Edit1, % A_Now "`r", % "ahk_class Notepad"
}
else
{
; I hope F2 can do its original action. How to?
Send {$F2} ; ??? No effect!
}
}
我的目的:
写Send {F2}
是不正确的,因为它会递归地触发我自己的F2:: ...
动作。
文档说添加$
前缀将抑制递归调用,但是, Send {$F2}
无效(好像我完全省略了这个Send
),当前活动的应用程序仅接收 F2 的 WM_KEYUP,没有 WM_KEYDOWN。
$ 前缀仅用于热键定义。 它强制使用键盘钩子,该钩子旨在过滤掉 AutoHotkey 脚本发送的键。
$F2:: send_f2_withcond()
send_f2_withcond() {
if WinExist("ahk_class Notepad")
ControlSend, Edit1, % A_Now "`r", % "ahk_class Notepad"
else
Send {F2}
}
您可以使用#IfWinExist大大简化此脚本。
#IfWinExist, ahk_class Notepad
F2::ControlSend Edit1, % A_Now "`r", % "ahk_class Notepad"
#IfWinExist
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.