gpt4 book ai didi

windows - 使用自动热键捕获右键单击+左键单击;意想不到的行为

转载 作者:可可西里 更新时间:2023-11-01 09:25:46 25 4
gpt4 key购买 nike

我想捕获按键事件“按下鼠标右键,然后按下鼠标左键”。自动热键没问题。但是,我仍然无法让鼠标右键单独工作。

1) 这行得通:

RButton & LButton::
Send X
Return

按预期工作:

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

2) 这行得通

~RButton & LButton::
Send Y
Return

按预期工作:

  • 如果我按下鼠标右键,然后按下鼠标左键,“Y”将发送到事件窗口
  • Authotkey 未捕获右键单击事件:当我单独按下鼠标右键或与鼠标左键一起按下时,上下文菜单确实出现。这是预期的结果

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

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

#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 发送的鼠标事件,因此在所有未经测试的应用程序中,我想使用 ~RButton & LButton 和 ~ 来传递右键单击事件

最佳答案

这里有一个支持右键拖动的!

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 发送事件的程序应该是那些依赖于低级 Hook 的程序......底部方法的真正问题是它只发送一次单击,而不是处理持有按钮。这种方法,以及分别向下和向上发送,都应该正确地做到这一点。

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


老东西

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

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

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.

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


因为我使用的是 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. RButton up 已发送,根据文档发送 RButton。因为 Firefox 在事件窗口检查和发送 RButton 之间的延迟中变为事件状态,所以 RButton 被发送到 Firefox。

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

我试图通过在 RButton 热键中添加一个额外的 IfWinNotActive 检查来修复这个错误,但它似乎不起作用。

关于windows - 使用自动热键捕获右键单击+左键单击;意想不到的行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10317568/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com