您可以使用;"来定义两个键(操纵杆按钮除外)的自定义组合.&"它们之间.在下面的示例中,您将按住 Numpad0 然后按第二个键来触发热键:Numpad0 &Numpad1::MsgBox 您在按住 Numpad0 的同时按下了 Numpad1.Numpad0 &Numpad2::运行记事本在上面的例子中,Numpad0 变成了前缀键;但这也会导致 Numpad0 在被自己按下时失去其原始/本机功能. 为避免这种情况,脚本可能会配置 Numpad0 以执行新操作,例如以下操作之一:Numpad0::WinMaximize A ;最大化活动/前景窗口.Numpad0::Send {Numpad0} ;使 Numpad0 的释放产生 Numpad0 击键.请参阅下面的评论.上述热键之一的存在会导致释放 Numpad0 以执行指定的操作,但前提是您在按住 Numpad0 的同时没有按下任何其他键.所以,按照那个例子:#If WinActive(ahk_class MozillaWindowClass")RButton &L按钮::发送 X返回R按钮::返回#If !WinActive(ahk_class MozillaWindowClass")RButton &L按钮::发送 Y返回RButton::Send {RButton}注意 RButton 需要一个在 WinActive 中什么都不做的变体,至少在我的测试中(见下文):RButton::return因为我使用的是 Autohotkey 标准,而不是 Autohotkey_L,所以我没有 #If 并且上述内容未经测试.以下我做了测试,它有效.#IfWinActive ahk_class MozillaWindowClassRButton &L按钮::发送 X返回R按钮::返回#IfWinNotActive ahk_class MozillaWindowClassRButton &L按钮::发送 Y返回RButton::Send {RButton}我注意到的一个有趣的错误是第二个 (NotActive) 变体偶尔适用于 Firefox:另一个窗口处于活动状态RButton 向下发送Firefox 未激活,因此处理了第二个变体(RButton 被按住,但延迟可能是难以察觉的,从毫秒到无限)Firefox 激活(仍然按住)RButton up 发送,根据文档发送 RButton .因为 Firefox 在活动窗口检查和发送 RButton 之间的延迟期间变为活动状态,所以 RButton 被发送到 Firefox.当 Firefox 和另一个窗口都可见,并且另一个窗口在单击时处于活动状态时,就会发生这种情况.我已尝试通过在 RButton 热键中添加额外的 IfWinNotActive 检查来修复此错误,但它似乎不起作用.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) this works:RButton & LButton:: Send XReturnworks as expected:If I press right mouse button, then left mouse button, "X" is sent to the active windowright-click event is captured by Authotkey: no context menu appears when I press the right mouse button alone. This is the intended outcome2) this works~RButton & LButton:: Send YReturnworks as expected:If I press right mouse button, then left mouse button, "Y" is sent to the active windowright-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 outcome3) Now I want to do different things depending on the active window.this does not work (careful: this will disable righ-click in every application)#If WinActive("ahk_class MozillaWindowClass")RButton & LButton:: Send XReturn#If !WinActive("ahk_class MozillaWindowClass")~RButton & LButton:: Send YReturndoes not work as expected:in Firefox left-right sends X, in other applications left-right sends Yhowever, right-click is disabled in every applicationWhat am I doing wrong here?edit: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 MozillaWindowClassRButton & LButton:: Send XReturnRButton::return#IfWinNotActive ahk_class MozillaWindowClass~$RButton::Hotkey, LButton, onwhile GetKeyState("RButton", "P") { continue }Hotkey, LButton, offReturnLButton::Send YReturnIt 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 is disabled at the start by the line at the top.Another way would have been to send {RButton Down} at the start of the hotkey and {RButton Up} at the end.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.The bug with active window described at the bottom of this answer still exists, but that's a problem with the #IfWin[Not]Active.Old stuffSee the documentation on the ampersand (emphasis mine):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 NotepadIn 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.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.So, following that example:#If WinActive("ahk_class MozillaWindowClass")RButton & LButton:: Send XReturnRButton::return#If !WinActive("ahk_class MozillaWindowClass")RButton & LButton:: Send YReturnRButton::Send {RButton}Note RButton requires a variant that does nothing in WinActive, at least with my testing (see below): RButton::returnSince 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 MozillaWindowClassRButton & LButton:: Send XReturnRButton::return#IfWinNotActive ahk_class MozillaWindowClassRButton & LButton:: Send YReturnRButton::Send {RButton}An interesting bug I've noticed is the second (NotActive) variant applies occasionally to Firefox:Another window is activeRButton down is sentFirefox is not active, so the second variant is processed<delay> (RButton is held down, though the delay could be imperceptible, in the order of milliseconds, to infinite)Firefox becomes active<delay> (still held down)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.This happens when both Firefox and another window are visible, and the other window is the active one at the time of the click.I've tried to fix this bug by adding an extra IfWinNotActive check within the RButton hotkey, but it did not seem to work. 这篇关于使用自动热键捕获右键单击+左键单击;意外行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-30 06:17