使用自动热键捕获右键单击和左键单击;意外行为 [英] capturing right-click+left-click with autohotkey; unexpected behaviour

查看:100
本文介绍了使用自动热键捕获右键单击和左键单击;意外行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想捕获关键事件按下鼠标右键,然后按下鼠标左键". autohotkey没问题.但是,我仍然无法让右键鼠标键单独工作.

I want to capture the key event "right mouse button pressed, then left mouse button pressed". No problem in autohotkey. However I am having trouble with still allowing the right-mouse key to work alone.

1)可行:

RButton & LButton::
    Send X
Return

按预期工作:

  • 如果我按下鼠标右键,然后按下鼠标左键,"X"将发送到活动窗口
  • 右键单击事件是通过Authotkey捕获的:,当我单独按下鼠标右键时,会出现上下文菜单.这是预期的结果
  • If I press right mouse button, then left mouse button, "X" is sent to the active window
  • right-click event is captured by Authotkey: no context menu appears when I press the right mouse button alone. This is the intended outcome

2)可行

~RButton & LButton::
    Send Y
Return

按预期工作:

  • 如果我按下鼠标右键,然后按下鼠标左键,"Y"将发送到活动窗口
  • Authotkey不能捕获
  • 右键单击事件:当我单独按下鼠标右键或同时按下鼠标左键时,会出现上下文菜单 .这是预期的结果
  • If I press right mouse button, then left mouse button, "Y" is sent to the active window
  • right-click event is not captured by Authotkey: context menu does appear when I press the right mouse button alone or together with the left button. This is the intended outcome

3)现在,我想根据活动窗口执行不同的操作.

3) Now I want to do different things depending on the active window.

这不起作用(小心:这将禁用在每个应用程序中的单击)

#If WinActive("ahk_class MozillaWindowClass")

RButton & LButton::
    Send X
Return


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

不能按预期工作:

  • 在Firefox中向左发送X,在其他应用程序中向左发送Y
  • 但是,每个应用程序
  • 中均禁用了右键单击功能
  • in Firefox left-right sends X, in other applications left-right sends Y
  • however, right-click is disabled in every application

我在这里做什么错了?

目标是这样的:我想使用RButton & LButton右键单击并单击全局全局热键.在经过测试兼容性的特定应用程序中,我希望右键单击左以抑制发送右键单击,然后使用自动快捷键手动发送右键单击.但是,由于某些应用程序可能无法处理由自动热键发送的鼠标事件,因此在所有未经测试的应用程序中,我想将~RButton & LButton与〜一起使用以传递所有右键单击事件

the goal is this: I want a global hotkey on Right+left-click with RButton & LButton . In specific applications that I have tested for compatibility, I want right+left click to suppress sending right-click, and then send right-click manually using autohotkey. However, since some applications might have trouble processing mouseevents sent by autohotkey, in all untested applications I want to use ~RButton & LButton with the ~ to pass throught right-click events

推荐答案

以下是支持右键单击拖动的一种!

Here's one that supports right click dragging!

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热键使用~,该键通常会通过点击.

It handles RButton manually. When RButton is pressed, it enables the LButton hotkey and waits for RButton to be released before deactivating it. The RButton hotkey uses ~, which passes the click through normally.

LButton在开头的顶部一行被禁用.

LButton is disabled at the start by the line at the top.

另一种方法是在热键的开头发送{RButton Down},在结束时发送{RButton Up}.

Another way would have been to send {RButton Down} at the start of the hotkey and {RButton Up} at the end.

作为对您的编辑的回应,唯一拒绝Autohotkey发送事件的程序应该是那些依赖于低级钩子的程序...............................................................按钮.此方法,并且分别上下发送,都应正确执行此操作.

In response to your edit, the only programs that reject Autohotkey's sent events should be those that rely on low level hooks... The real trouble with the method down at the bottom is it only sends a single click, not processing holding the button. This method, and sending down and up separately, should both do that properly.

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

The bug with active window described at the bottom of this answer still exists, but that's a problem with the #IfWin[Not]Active.

请参见&符号上的文档(重点是我):

See the documentation on the ampersand (emphasis mine):

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

You can define a custom combination of two keys (except joystick buttons) by using " & " between them. In the below example, you would hold down Numpad0 then press the second key to trigger the hotkey:

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

在上面的示例中,Numpad0成为前缀键; 为避免这种情况,脚本可以将Numpad0配置为执行新操作,例如以下之一:

In the above example, Numpad0 becomes a prefix key; but this also causes Numpad0 to lose its original/native function when it is pressed by itself. To avoid this, a script may configure Numpad0 to perform a new action such as one of the following:

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的同时未按下任何其他键.

The presence of one of the above hotkeys causes the release of Numpad0 to perform the indicated action, but only if you did not press any other keys while Numpad0 was being held down.

因此,按照该示例:

#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

Note RButton requires a variant that does nothing in WinActive, at least with my testing (see below): RButton::return

由于我使用的是Autohotkey标准而不是Autohotkey_L,因此我没有#If,并且上述内容未经测试.我进行了以下 did 测试,并且可以正常工作.

Since I'm using Autohotkey standard, not Autohotkey_L, I don't have #If and the above was untested. The following I did test, and it works.

#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:

An interesting bug I've noticed is the second (NotActive) variant applies occasionally to Firefox:

  1. 另一个窗口处于活动状态
  2. RButton down 已发送
  3. Firefox未激活,因此第二个变体已处理
  4. < delay> (RButton处于按下状态,但延迟可能难以察觉,以毫秒为单位,是无限的)
  5. Firefox处于活动状态
  6. < delay> (仍然按住)
  7. RButton up 已发送,根据文档发送RButton.由于Firefox在活动窗口检查和发送RButton之间的延迟中处于活动状态,因此将RButton发送到Firefox.
  1. Another window is active
  2. RButton down is sent
  3. Firefox is not active, so the second variant is processed
  4. <delay> (RButton is held down, though the delay could be imperceptible, in the order of milliseconds, to infinite)
  5. Firefox becomes active
  6. <delay> (still held down)
  7. RButton up is sent, which sends RButton as per the documentation. Because Firefox became active in the delay between the active window check and when RButton is sent, RButton is sent to Firefox.

当Firefox和另一个窗口都可见并且单击时另一个窗口处于活动状态时,就会发生这种情况.

This happens when both Firefox and another window are visible, and the other window is the active one at the time of the click.

我试图通过在RButton热键中添加一个额外的IfWinNotActive检查来修复此错误,但是它似乎没有用.

I've tried to fix this bug by adding an extra IfWinNotActive check within the RButton hotkey, but it did not seem to work.

这篇关于使用自动热键捕获右键单击和左键单击;意外行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆