【问题标题】:How can I use autohotkey to stop WASD movement while holding down the left mouse button?如何在按住鼠标左键的同时使用 autohotkey 停止 WASD 移动?
【发布时间】:2021-05-15 13:45:56
【问题描述】:

我有兴趣在按住鼠标左键的同时禁用 w、a、s 和 d 键。 (诸如 cs:go 和 valorant 等游戏会在移动时惩罚射击,所以我想完全排除这种情况)。 我刚刚了解了自动热键,所以如果我用这种代码尝试冒犯了某人,我很抱歉(这显然不起作用):

while (GetKeyState("LButton", "P"))
{
    w::return
    a::return
    s::return
    d::return       
} 

谢谢,非常感谢!

【问题讨论】:

    标签: autohotkey


    【解决方案1】:

    我只想添加@Spyre 暗示的解决方案。当您使用 #If 指令时,脚本确实会变得更小,并且当 if 语句失败时,热键不会触发,因此它不会添加到您的整体 hotkeys per interval 中。这是我的脚本版本:

    #If GetKeyState("LButton", "P")
    w::
    a::
    s::
    d::
    Return
    

    【讨论】:

      【解决方案2】:

      使用#If (docs)

      #If, GetKeyState("LButton")
      w::
      a::
      s::
      d::return  
      #If
      

      如果#If 给您带来麻烦(就像文档中警告的那样)(如果您的脚本如此小而简单,则不会发生),您会想要打开和关闭热键Hotkeycommand.
      例如:

      ~LButton::ConsumeASDW("On")     ;press down
      LButton Up::ConsumeASDW("Off")  ;release
      
      ConsumeASDW(OnOff)
      {
          for each, key in StrSplit("asdw")
              Hotkey, % key, Consumer, % OnOff
      }
      
      Consumer()
      {
          Return
      }
      

      【讨论】:

        【解决方案3】:

        你的想法是对的,但你目前拥有的将是 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 指令可能有一些更有效的方法来声明热键的条件,但这应该是您需要的工作。

        【讨论】:

          猜你喜欢
          • 2010-12-31
          • 2013-06-07
          • 1970-01-01
          • 1970-01-01
          • 2014-04-09
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-02-14
          相关资源
          最近更新 更多