Windows 简单条件传递
想知道我是否在AHK中遗漏了一些基本的东西:有没有一种方法可以对任何鼠标或键盘操作执行简单的条件传递,这样如果条件失败,操作就可以通过 比如:Windows 简单条件传递,windows,mouseevent,keyboard-shortcuts,autohotkey,key-bindings,Windows,Mouseevent,Keyboard Shortcuts,Autohotkey,Key Bindings,想知道我是否在AHK中遗漏了一些基本的东西:有没有一种方法可以对任何鼠标或键盘操作执行简单的条件传递,这样如果条件失败,操作就可以通过 比如: LButton:: if(WinActive("ahk_class Notepad")) { ; Do something cool } else { ; Pass through } 给我带来特别麻烦的是,必须通过LButton。当左键单击是拖动操作的开始时,“最干净”的技术似乎失败了(请参见底部的非工作脚本)。
LButton::
if(WinActive("ahk_class Notepad")) {
; Do something cool
}
else {
; Pass through
}
给我带来特别麻烦的是,必须通过LButton
。当左键单击是拖动操作的开始时,“最干净”的技术似乎失败了(请参见底部的非工作脚本)。我有一个解决办法,但它是冗长的
我试过的
我有一个可行的解决方案,但它相当冗长。下面,为了演示的目的,我将它改编成一个简单的记事本示例。演示脚本的作用:
- 在记事本中,如果您在文本框中单击,则会收到警报,并且您的单击将被禁用。但是,您可以单击菜单
- 在其他地方,单击功能正常
$
修饰符的方法,但这种方法不起作用(请参见底部)
注释
- 脚本使用
而不是单击向下
,因为否则无法执行拖动操作。这些都是实际应用中需要的,可以通过调整窗口大小在记事本中进行测试单击
- 我没有将
包装在LButton
中,因为“LButton Up”需要应用于所有类。为什么?当您从记事本切换到另一个应用程序时,单击向下通过记事本测试,但单击向上失败,因为您现在处于不同的窗口中If-WinActive
#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
使用$
的非工作脚本
这种方法不起作用,因为记事本窗口无法再调整大小:“通过”似乎是单击,而不是在需要时单击(拖动操作)
#如果…
指令用于在特定条件下仅触发热键。这当然意味着:如果不满足给定的条件,热键例程将不会被调用,并且这些键将通过(它们将像本地键事件那样通过)
你的例子是:
; $ prevents the hotkey from triggering itself
$LButton::
if(WinActive("ahk_class Notepad")) {
; Do something cool
} else {
; Pass through
Send, LButton
}
return
可以很容易地写成:
#IfWinActive, ahk_class Notepad
LButton::
; Only the cool stuff goes here
return
#IfWinActive
针对您的问题,您还可以将#If
与表达式结合使用,以确定任意条件的组合,即检查用户是否试图点击记事本窗口中的文本框:
#If WinActive("ahk_class Notepad") && MouseOver() = "Edit1"
LButton::
SplashTextOn 300, 100, AutoHotkey Message, You can play with the menus`,`nbut not the text box.
Sleep 3000
SplashTextOff
Return
#If
MouseOver() {
MouseGetPos, , , , curControl
return curControl
}
首先,非常感谢您的来信<代码>$是我尝试过的事情之一,虽然它适用于普通的
if
,但我无法使它适用于发布在此处的演示脚本,该脚本禁止在鼠标位于某个控件上时单击。我编辑了这个问题,将不起作用的脚本粘贴在底部。很可能你的想法是对的,而我错过了一些小东西@zx81我想我现在明白你的问题了…请查看更新。如果行得通,我很乐意详细说明。太棒了。你明白了。我忽略了检查函数中位置的关键思想。支持和接受。非常感谢。:)
#If WinActive("ahk_class Notepad") && MouseOver() = "Edit1"
LButton::
SplashTextOn 300, 100, AutoHotkey Message, You can play with the menus`,`nbut not the text box.
Sleep 3000
SplashTextOff
Return
#If
MouseOver() {
MouseGetPos, , , , curControl
return curControl
}