AHK 发送密钥按密钥定义

问题描述 投票:0回答:2

我在使用 Ahk 的热键时遇到问题。 我使用此代码来激活 if

activated = 1
一段代码


    l::
         if (activated = 1)
         {
              send, Hello there
         }
    else
        send, l

问题是如果

activated = 0
l 键不会按下,因为它会自行激活。 有谁知道如何解决它? 谢谢SpaceBroetchen

autohotkey
2个回答
1
投票

$
前缀(文档)就是为此目的。
使热键不会自行触发。
另外,我推荐SendInput,它是更快、更可靠的发送模式。

$l::
    if (activated = 1)
        SendInput, Hello there
    else
        SendInput, l
return

不过,似乎更好的选择是使用上下文相关的热键。
如果您想告诉我有关此

activated
检查的更多信息,我可能会推荐一种更好的方法。


0
投票

正如另一个答案中提到的,更好的解决方案是使用 #If 指令使热键上下文敏感。

那么就不需要else语句来执行普通的按下了:

#If (activated = 1)

    $l::SendInput, Hello there

#If ; turn off context sensitivity
© www.soinside.com 2019 - 2024. All rights reserved.