gpt4 book ai didi

windows - 简单的条件传递

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

想知道我是否遗漏了 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

最佳答案

#If... 指令用于使热键仅在特定条件下触发。这当然意味着:如果不满足给定的条件,则不会调用热键例程并且键会通过(并且它们会像本地键事件那样通过)。

你的例子:

; $ 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
}

关于windows - 简单的条件传递,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39829811/

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