我正在自我回答这个问题,因为我在互联网上看到过这个问题,但几乎没有有用的答案,而且在 Stack Overflow 上也绝对找不到我能找到的解决方案。
示例代码
考虑一下这段代码,它只写了几行 shell 命令:
^0::
SetKeyDelay, 0, 0
myWindow = ahk_exe Notepad.exe
ControlSend, , set c=".cshrc-andrew.cheong"`n, %myWindow%
ControlSend, , set v=".vimrc-andrew.cheong"`n, %myWindow%
ControlSend, , foreach d ( /userhome/andrew.cheong /home/$USER /data/$USER )`n, %myWindow%
ControlSend, , if ( -e $d/$c ) source $d/$c`n, %myWindow%
ControlSend, , if ( -e $d/$v ) alias vim "vim -N -u $d/$v"`n, %myWindow%
ControlSend, , end`n, %myWindow%
Return
I'm writing the commands to Notepad to show that it is not an issue limited to terminal applications like PuTTy or xterm. It's easy to think so, since these applications sometimes have laggy behavior.
示例输出
具体使用时SetKeyDelay, 0, 0
为了快速“打字”,我会遇到各种奇怪的行为,例如:
-
双引号替换为单引号。括号被 9 和 0 替换。美元符号被 4 取代。
set c=".cshrc-andrew.cheong'
set v=".vimrc-andrew.cheong"
foreach d ( /userhome/andrew.cheong /home/$USER /data/$USER )
if 9 -e 4d/4c 0 source 4d/4c
if ( -e $d/$v ) alias vim 'vim -n -u 4d/4v'
end
-
破折号替换为下划线。案例变化。
set c='.cshrc-andrew.cheong"
set v='.vimrc-andrew.cheong'
foreach d ( /userhome/andrew.cheong /home/4user /data/$USER )
if 9 -e 4d/$C ) source 4d/$c
if 9 _e $d/$v ) alias vim 'vim -N -u $d/$v"
end
-
句点替换为 > 。更多案例变化。
set c=".cshrc-andrew.cheong"
set v=">VIMrc-andrew.cheong"
foreach d ( /userhome/andrew.cheong /home/$USER /data/$USER )
if 9 -e $d/$c ) source 4d/$c
if ( -e $d/$V ) alias vim "vim -N -u $d/$v"
end
It's obvious the issue has something to do with the Shift modifier, as if it's being randomly turned on or off.
为什么会发生这种情况,我们该如何解决?
注意使用时没有问题Send
及其变体。这个问题具体出现在ControlSend
,需要将输入发送到特定控件或未聚焦的窗口。