ctrl+s 未在自动热键脚本中发送

ctrl+s not being sent in autohotkey script

即按 ctrl+s 应该激活 ctrl+s...以下不起作用。更简单的也不行 发送输入,^s。目标是让 ctrl+s 保存当前文档,然后通过更多代码加载另一个文档,但保存部分永远不起作用。错误的代码,取决于我在哪里睡觉或不睡觉, returns s或 shift s(无论如何在1个代码编辑器中)或什么都不做。我基本上想要一个模仿自己的热键。

F4::ExitApp  
<^s::  
send, {lctrl down}  
SLEEP 300  
SEND s  
SLEEP 300  
SEND {lctrl up}  
return  

我认为您的程序 运行 遇到的问题是让 ^s 在其自身内部发送另一个 ^s 正在创建一个无限递归循环,其中任何东西都无法 运行 过去你调用 ^s 的地方。为了防止这种情况,我们可以像这样使用 $ 修饰符:

$<^s::  
SendInput ^s
return  

来自the Modifier section of the docs的相关部分:

This is usually only necessary if the script uses the Send command to send the keys that comprise the hotkey itself, which might otherwise cause it to trigger itself. The $ prefix forces the keyboard hook to be used to implement this hotkey, which as a side-effect prevents the Send command from triggering it. The $ prefix is equivalent to having specified #UseHook somewhere above the definition of this hotkey.


编辑:即使我删除 $ 修饰符,它对我来说似乎也能正常工作。测试以下代码表明在 SendInput 语句之前、之后或期间执行代码似乎没有问题。

<^s::  
MsgBox no
SendInput, ^s
MsgBox yes
return

也许检查你的 AHK 版本或安装?