无法在 AutoHotkey 中切换

问题描述

我正在尝试将“]”切换为当我按“p”时它按“e”总共 3 次,间隔为 10 毫秒。如果我只想按“t”,请关闭

我有这个但设置为“p”只是为了快速按“e”3次但没有切换,以防我想正常输入“t”。

#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.

SetKeyDelay,10,10 ; first is delay between keypresses,and second is press duration

; we are using ControlSend here because Send and sendinput is not affected by SetKeyDelay.


p::
ControlSend,e,A 
ControlSend,A
return,/::
ExitApp
return,

我可以在切换时获得帮助吗?

解决方法

在我看来,您只是想切换正在启用的热键。
使用 Suspend(docs) 很容易做到这一点。

另外,这是错误的:
我们在这里使用 ControlSend 是因为 Send 和 SendInput 不受 SetKeyDelay 的影响。
SetKeyDelay(docs) 可以正常使用 Send。您实际上是在使用 SendMode Input(docs) 将默认发送模式更改为 SendInput。这就是它不起作用的原因。

我知道前 4 行是在您非手动创建新 ahk 文件时自动生成的。
很高兴知道他们实际上在做什么。
所以不要ControlSend,除非你真的需要ControlSend,切换到正常的Send

另外,您对 SetKeyDelay(docs) 的使用在那里有点奇怪。
它旨在为单个命令添加延迟的能力。根据您的方法,您还可以在中间插入 Sleep

固定/修改脚本:

SetKeyDelay,10,10

p::Send,eee
]::Suspend
/::ExitApp