Autohotkey - 在屏幕上的特定位置单击时发送密钥
Autohotkey - Send key when clicked at certain position on the screen
我正在尝试编写 AutoHotkey 代码,当在屏幕中的某个位置(范围如下所示)单击鼠标左键时,该代码会导致发送 Space 键。如果在范围外单击鼠标,将导致默认行为。下面的代码不起作用。例如,如果我单击 ypos 小于 170 的应用程序的关闭按钮,什么也不会发生。请求 help/inputs。谢谢
#IfWinActive ahk_class IrfanView
LButton::
MouseGetPos,xpos, ypos
If (ypos >170 and ypos <570)
{
Msgbox %ypos%
Send, {Space}
}
#IfWinActive
Return
你几乎成功了。
由于您处理的是鼠标左键单击,因此鼠标方面不会发生任何进一步的事情。
所以你必须像这样重新发出点击事件:
#IfWinActive ahk_class IrfanView
LButton::
MouseGetPos, xpos, ypos
If (ypos >170 and ypos <570) {
Msgbox %ypos%
Send, {Space}
}
Else {
Click
}
Return
另请注意,我删除了您的第二个 #ifWinActive
这不应该发生在 return 语句之前。
如果您只是为 IrfanView 添加热键,则根本不需要该语句。如果像我一样,您在一个大脚本中捕获不同 windows/programs 的键,那么请遵循这样的模式
#IfWinActive ahk_class CabinetWClass ;Windows Explorer
...keydefs here...
#IfWinActiveahk_class XLMAIN ;Excel
...keydefs here...
#IfWinActive ahk_exe OUTLOOK.exe ;Outlook
...keydefs here...
#IfWinActive ;Keys that work anywhere
...all other keydefs here...
我正在尝试编写 AutoHotkey 代码,当在屏幕中的某个位置(范围如下所示)单击鼠标左键时,该代码会导致发送 Space 键。如果在范围外单击鼠标,将导致默认行为。下面的代码不起作用。例如,如果我单击 ypos 小于 170 的应用程序的关闭按钮,什么也不会发生。请求 help/inputs。谢谢
#IfWinActive ahk_class IrfanView
LButton::
MouseGetPos,xpos, ypos
If (ypos >170 and ypos <570)
{
Msgbox %ypos%
Send, {Space}
}
#IfWinActive
Return
你几乎成功了。
由于您处理的是鼠标左键单击,因此鼠标方面不会发生任何进一步的事情。
所以你必须像这样重新发出点击事件:
#IfWinActive ahk_class IrfanView
LButton::
MouseGetPos, xpos, ypos
If (ypos >170 and ypos <570) {
Msgbox %ypos%
Send, {Space}
}
Else {
Click
}
Return
另请注意,我删除了您的第二个 #ifWinActive
这不应该发生在 return 语句之前。
如果您只是为 IrfanView 添加热键,则根本不需要该语句。如果像我一样,您在一个大脚本中捕获不同 windows/programs 的键,那么请遵循这样的模式
#IfWinActive ahk_class CabinetWClass ;Windows Explorer
...keydefs here...
#IfWinActiveahk_class XLMAIN ;Excel
...keydefs here...
#IfWinActive ahk_exe OUTLOOK.exe ;Outlook
...keydefs here...
#IfWinActive ;Keys that work anywhere
...all other keydefs here...