【问题标题】:Autohotkey sends default button action if the cursor is over an inactive window如果光标位于非活动窗口上,自动热键会发送默认按钮操作
【发布时间】:2018-04-24 06:47:32
【问题描述】:

我编写了以下代码,以便重新映射第 4 和第 5 鼠标按钮以向上滚动和向下滚动:

代码:

XButton2::
While GetKeyState("XButton2","P")
{
Send {WheelUp 1}
Sleep 120
}
return


XButton1::
While GetKeyState("XButton1","P")
{
Send {WheelDown 1}
Sleep 120
}
return

问题:

如果光标在活动窗口上,一切正常。

但是,当我在非活动窗口上单击 XButton1(第 4 个鼠标按钮)或 XButton2(第 5 个鼠标按钮)时,有时它会将默认操作发送到该窗口。

例如,如果光标在 Chrome 上(非活动)并且活动窗口是任务管理器,它将发送默认的“page back”操作而不是脚本中指定的“向下滚动”,但是当我点击 Chrome并使其活跃,一切正常

问题:

有没有办法只禁用默认操作?因此,如果您没有按住按钮 (While GetKeyState("XButton1","P")),它什么也不做?

【问题讨论】:

  • 尝试使用“以管理员身份运行”运行脚本
  • 尝试将活动窗口 (WinGet) 与光标下的窗口 (MouseGetPos) 进行比较。如果它们不匹配,则什么也不做。
  • @MCL 看起来您的解决方案到目前为止有效,谢谢
  • 如果您有解决方案,请考虑将其作为答案发布在这里并接受它作为解决方案。这样,其他人可能会从中获利。

标签: autohotkey


【解决方案1】:

试试这个。它使热键仅在某些窗口处于活动状态时才起作用,如果不是,则不返回任何内容。我没有额外的鼠标按钮,所以我用常规键盘键对其进行了测试,它工作正常。

loop
 {
 sleep,50
 #if WinActive("ahk_exe chrome.exe") or WinActive("ahk_exe explorer.exe") ;;hotkeys work only if chrome.exe or explorer.exe is active
  {
  XButton2::
  While GetKeyState("XButton2","P")
   {
   Send {WheelUp 1}
   Sleep 120
   }
  XButton1::
  While GetKeyState("XButton1","P")
   {
   Send {WheelDown 1}
   Sleep 120
   }
  }
 #if ! WinActive("ahk_exe chrome.exe") ;;if chrome isn't active XButton1 and XButton2 return nothing
  {
  XButton1::return
  XButton2::return
  }
 }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多