热键不循环发送命令

问题描述

我有这个代码,我想每当我按住 ctrl+n 时,它就会点击并拖动。它不会在发送命令到位的情况下循环。它只运行一次,除非我松开 ctrl 和 n 并再次按下。如果我将它们注释掉,当我按住它时,热键循环非常好。这是我的脚本:

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn  ; Enable warnings to assist with detecting common errors.
; SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.


^n::
CoordMode,Mouse,Screen
Send {LButton down} ;if i comment these two out it works fine
MouseMove,30,20,R
Send {LButton up} ; ditto
return

解决方法

问题是 ctrl 键。当按下它停止热键的新执行。我在没有 ctrl 前缀的情况下尝试了它,只使用了 n:: 并且效果很好。如果您按 ctrl+n 然后释放它然后再次按下它,它也可以工作。 无论如何,当您在前面添加 Hotkey Modifier $ 符号时,它会按您的意愿工作。

热键修饰符$解释:

这通常仅在脚本使用 Send 命令发送包含热键本身的键时才需要,否则可能会导致它自行触发。 $ 前缀强制使用键盘钩子来实现这个热键,作为一个副作用,它会阻止发送命令触发它。 $ 前缀相当于在此热键的定义上方某处指定了#UseHook。

更多信息: https://www.autohotkey.com/docs/Hotkeys.htm

$^n::
CoordMode,Mouse,Screen
Send {LButton down}
MouseMove,30,20,R
Send {LButton up}
return