【发布时间】:2016-10-03 10:48:05
【问题描述】:
想知道我是否遗漏了 AHK 中的一些基本内容:有没有办法对任何鼠标或键盘操作进行简单的条件传递,这样如果条件失败,操作就会通过?
类似:
LButton::
if(WinActive("ahk_class Notepad")) {
; Do something cool
}
else {
; Pass through
}
给我带来特别麻烦的是必须通过LButton 的情况。当左键单击开始拖动操作时,“最干净”的技术似乎失败了(请参阅底部的非工作脚本)。我有一个解决方法,但它很冗长。
我尝试过的
我有一个可行的解决方案,但它相当冗长。下面,我将它改编为一个简单的记事本示例,用于演示目的。演示脚本的作用:
- 在记事本中,如果您单击文本框,您会收到一条警报并且您的单击被禁用。不过,您可以点击菜单。
- 其他地方,点击功能正常。
我还尝试了一种使用 $ 修饰符的方法,但它不起作用(请参阅底部)。
备注
- 脚本使用
Click Down而不是Click,否则无法进行拖动操作。这些在实际应用中是必需的,可以通过调整窗口大小在记事本中进行测试。 - 我没有将
LButton包装在If WinActive中,因为'LButton Up` 需要申请所有课程。为什么?当您从记事本切换到另一个应用程序时,单击向下通过了记事本测试,但单击向上失败,因为您现在处于不同的窗口中。
工作脚本
#NoEnv ; Recommended for all scripts. Avoids checking empty variables to see if they are environment variables.
LButton::
if(WinActive("ahk_class Notepad")) {
MouseGetPos, x, y, ovw, control
if(control = "Edit1") {
SplashTextOn 300, 100, AutoHotkey Message, You can play with the menus`,`nbut not the text box.
Sleep 3000
SplashTextOff
}
else { ; pass the click through
; The reason we Click down is that a plain Click doesn't work
; for actions where hold the button down in order to drag.
Click down
}
}
else {
Click down
}
Return
; The LButton section holds the down state, so we need to allow it Up
LButton Up::Click up
使用$的非工作脚本
此方法不起作用,因为无法再调整记事本窗口的大小:“传递”似乎是单击,而不是在需要时单击(拖动操作)。
#NoEnv ; Recommended for all scripts. Avoids checking empty variables to see if they are environment variables.
#IfWinActive ahk_class Notepad
$LButton::
MouseGetPos, x, y, ovw, control
if(control = "Edit1") {
SplashTextOn 300, 100, AutoHotkey Message, You can play with the menus`,`nbut not the text box.
Sleep 3000
SplashTextOff
}
else { ; pass the click through
Send {LButton}
}
Return
#IfWinActive
【问题讨论】:
标签: windows mouseevent keyboard-shortcuts autohotkey key-bindings