问题描述
我想为我的字典应用程序编写一个脚本,这样当我短时间按住 j 键时,它就会激活现有的 KMPlayer 窗口并发送空间并最大化它(通过发送中间鼠标按钮),如果 KMPlayer 不存在,它会发送 Alt+Esc。
这是我的脚本:
#IfWinActive Oxford Advanced Learner's Dictionary
~$j::
KeyWait,j,T0.2
If (ErrorLevel)
{
If WinExist ("KMPlayer 64X")
{
WinActivate
sleep,50
sendinput,{space}
sleep,50
sendinput,{MButton}
}
else
{
sendinput,!{Esc}
}
}
return
但不幸的是,当我按住字典搜索栏中的按钮时,它只是输入类似
j jjjjjj j jjj j jjjjjj j jj
而不是执行功能。我不知道如何修复脚本。
解决方法
我通过在 autohotkey.com (this post ) 上提问找到了答案。
这是用户@mikeyww 解决我的问题的脚本:
#IfWinActive Oxford Advanced Learner
$j::
KeyWait,j,T.2
If !ErrorLevel
{ Send j
Return
}
If WinExist("ahk_exe KMPlayer64.exe")
{ WinActivate
Send {Space}{Enter}
} Else Send !{Esc}
KeyWait,j
Return
#IfWinActive