如何在按住鼠标左键的同时使用 autohotkey 停止 WASD 移动?
How can I use autohotkey to stop WASD movement while holding down the left mouse button?
我想在按住鼠标左键的同时禁用 w、a、s 和 d 键。
(cs:go 和 valorant 等游戏会在移动时惩罚射击,所以我想完全排除这种情况)。
我刚刚了解了 autohotkey,所以如果我用这种代码尝试冒犯了某人(这显然行不通),我很抱歉:
while (GetKeyState("LButton", "P"))
{
w::return
a::return
s::return
d::return
}
谢谢,非常感谢!
你的想法是正确的,但你目前拥有的将是 auto-executed 在脚本的开头,并且在 运行 检查 LMB 是否被持有之后下来,脚本将停止做任何事情。
我的方法是,将 $
修饰符与热键一起使用,以确保热键不会递归地触发自身。
$w::
if (GetKeyState("LButton", "P"))
return
Send w
return
$a::
if (GetKeyState("LButton", "P"))
return
Send a
return
$s::
if (GetKeyState("LButton", "P"))
return
Send s
return
$d::
if (GetKeyState("LButton", "P"))
return
Send d
return
可能有一些更有效的方法来使用 #If
指令声明热键的条件,但这应该是您需要的工作。
我只想添加@Spyre 暗示的解决方案。当您使用 #If
指令时,脚本确实会变得更小,并且当 if 语句失败时,热键不会触发,因此它不会增加您的整体 hotkeys per interval。这是我的脚本版本:
#If GetKeyState("LButton", "P")
w::
a::
s::
d::
Return
使用#If
(docs):
#If, GetKeyState("LButton")
w::
a::
s::
d::return
#If
如果 #If
给您带来麻烦(如文档中的警告)(如果您的脚本如此小而简单,则不会发生),您需要打开并使用 Hotkey
command.
关闭热键
例如:
~LButton::ConsumeASDW("On") ;press down
LButton Up::ConsumeASDW("Off") ;release
ConsumeASDW(OnOff)
{
for each, key in StrSplit("asdw")
Hotkey, % key, Consumer, % OnOff
}
Consumer()
{
Return
}
我想在按住鼠标左键的同时禁用 w、a、s 和 d 键。 (cs:go 和 valorant 等游戏会在移动时惩罚射击,所以我想完全排除这种情况)。 我刚刚了解了 autohotkey,所以如果我用这种代码尝试冒犯了某人(这显然行不通),我很抱歉:
while (GetKeyState("LButton", "P"))
{
w::return
a::return
s::return
d::return
}
谢谢,非常感谢!
你的想法是正确的,但你目前拥有的将是 auto-executed 在脚本的开头,并且在 运行 检查 LMB 是否被持有之后下来,脚本将停止做任何事情。
我的方法是,将 $
修饰符与热键一起使用,以确保热键不会递归地触发自身。
$w::
if (GetKeyState("LButton", "P"))
return
Send w
return
$a::
if (GetKeyState("LButton", "P"))
return
Send a
return
$s::
if (GetKeyState("LButton", "P"))
return
Send s
return
$d::
if (GetKeyState("LButton", "P"))
return
Send d
return
可能有一些更有效的方法来使用 #If
指令声明热键的条件,但这应该是您需要的工作。
我只想添加@Spyre 暗示的解决方案。当您使用 #If
指令时,脚本确实会变得更小,并且当 if 语句失败时,热键不会触发,因此它不会增加您的整体 hotkeys per interval。这是我的脚本版本:
#If GetKeyState("LButton", "P")
w::
a::
s::
d::
Return
使用#If
(docs):
#If, GetKeyState("LButton")
w::
a::
s::
d::return
#If
如果 #If
给您带来麻烦(如文档中的警告)(如果您的脚本如此小而简单,则不会发生),您需要打开并使用 Hotkey
command.
关闭热键
例如:
~LButton::ConsumeASDW("On") ;press down
LButton Up::ConsumeASDW("Off") ;release
ConsumeASDW(OnOff)
{
for each, key in StrSplit("asdw")
Hotkey, % key, Consumer, % OnOff
}
Consumer()
{
Return
}