捕获右键单击+左键单击autohotkey;意外行为

时间:2012-04-25 10:41:34

标签: windows mouse autohotkey

我想捕捉按键事件“按下鼠标右键,然后按下鼠标左键”。 autohotkey没问题。但是我仍然无法使用鼠标右键单独工作。

1)这有效:

RButton & LButton::
    Send X
Return

按预期工作:

  • 如果我按下鼠标右键,则鼠标左键,“X”被发送到活动窗口
  • 右键单击事件由Authotkey捕获:当我单独按下鼠标右键时,会出现上下文菜单。这是预期的结果

2)这是有效的

~RButton & LButton::
    Send Y
Return

按预期工作:

  • 如果我按下鼠标右键,则鼠标左键,“Y”被发送到活动窗口
  • Authotkey未捕获右键单击事件:单独按下鼠标右键或与左键同时显示上下文菜单确实。这是预期的结果

3)现在我想根据活动窗口做不同的事情。

这不起作用(小心:这将禁用每个应用程序中的righ-click)

#If WinActive("ahk_class MozillaWindowClass")

RButton & LButton::
    Send X
Return


#If !WinActive("ahk_class MozillaWindowClass")
~RButton & LButton::
    Send Y
Return

无法正常工作:

    Firefox中的
  • 左右发送X,其他应用程序左右发送Y
  • 但是,在每个应用程序
  • 中禁用了右键单击

我在这里做错了什么?


编辑:

目标是:我想要一个全局热键,右键+左键单击RButton & LButton。在我测试兼容性的特定应用程序中,我想要右键+左键单击以禁止发送右键单击,然后使用autohotkey手动右键单击。但是,由于某些应用程序可能无法处理由autohotkey发送的mouseevent,因此在所有未经测试的应用程序中,我想使用~RButton & LButton和〜来通过右键单击事件

1 个答案:

答案 0 :(得分:3)

这是支持右键单击拖动的一个!

Hotkey, LButton, off

#IfWinActive ahk_class MozillaWindowClass
RButton & LButton::
    Send X
Return

RButton::return

#IfWinNotActive ahk_class MozillaWindowClass
~$RButton::
Hotkey, LButton, on
while GetKeyState("RButton", "P") {
    continue
    }
Hotkey, LButton, off
Return

LButton::Send Y
Return

手动处理RButton。按下RButton后,它会启用LButton热键并等待RButton释放,然后再将其停用。 RButton热键使用~,正常通过点击。

LButton在开头被顶部的行禁用。

另一种方法是在热键开头发送{RButton Down},最后发送{RButton Up}

为了回应你的编辑,拒绝Autohotkey发送事件的唯一程序应该是那些依赖于低级钩子的程序......底部方法的真正问题是它只发送一次单击,而不是处理持有按钮。这种方法,以及分别向下和向上发送,都应该正确地做到这一点。

此答案底部描述的活动窗口错误仍然存​​在,但这是#IfWin[Not]Active的问题。


旧东西

参见documentation on the ampersand(强调我的):

  

您可以在它们之间使用“&”来定义两个键(操纵杆按钮除外)的自定义组合。在下面的示例中,您将按住Numpad0,然后按第二个键以触发热键:

Numpad0 & Numpad1::MsgBox You pressed Numpad1 while holding down Numpad0.
Numpad0 & Numpad2::Run Notepad
     

在上面的例子中,Numpad0成为前缀键;但这也会导致Numpad0在单独按下时失去其原始/本机功能。为避免这种情况,脚本可以配置Numpad0执行新操作,例如以下之一:

Numpad0::WinMaximize A   ; Maximize the active/foreground window.
Numpad0::Send {Numpad0}  ; Make the release of Numpad0 produce a Numpad0 keystroke. See comment below.
     

上述热键之一的存在会导致释放Numpad0以执行指示的操作,但前提是当Numpad0被按下时没有按任何其他键。

所以,遵循这个例子:

#If WinActive("ahk_class MozillaWindowClass")

RButton & LButton::
    Send X
Return

RButton::return

#If !WinActive("ahk_class MozillaWindowClass")
RButton & LButton::
    Send Y
Return

RButton::Send {RButton}

注意RButton要求变体在WinActive中不执行任何操作,至少在我的测试中是这样的(见下文):RButton::return


由于我使用的是Autohotkey标准,而不是Autohotkey_L,我没有#If,而且上面的内容未经测试。以下我做了测试,它可以工作。

#IfWinActive ahk_class MozillaWindowClass
RButton & LButton::
    Send X
Return

RButton::return


#IfWinNotActive ahk_class MozillaWindowClass
RButton & LButton::
    Send Y
Return

RButton::Send {RButton}

我注意到的一个有趣的错误是第二个(NotActive)变体偶尔适用于Firefox:

  1. 另一个窗口处于活动状态
  2. RButton down 已发送
  3. Firefox处于非活动状态,因此处理了第二个变体
  4. <延迟> (RButton被按下,虽然延迟可能是不可察觉的,在毫秒级到无限级)
  5. Firefox变为活动
  6. <延迟> (仍然坚持下来)
  7. 发送
  8. RButton up ,根据文档发送RButton。由于Firefox在活动窗口检查和发送RButton之间的延迟时变得活跃,因此RButton将发送到Firefox。
  9. 当Firefox和另一个窗口都可见时,会发生这种情况,而另一个窗口是点击时的活动窗口。

    我试图通过在IfWinNotActive热键中添加额外的RButton支票来修复此错误,但它似乎无效。