AutoHotKey - 如何在 IF 语句上使用组合键?
AutoHotKey - How do I use a key combination on an IF statement?
我正在尝试禁用 Alt + F4,但我想在按下 Windows 键 + Q 时启用它。到目前为止,我得到的这个不起作用。
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
if (#q)
{
Send !{F4}
Return
} else {
!F4::Return
}
; autoexecute section:
Alt_F4_enabled:= false
; ...
return ; end of autoexecute section
#q:: Alt_F4_enabled:= true
!F4::
If Alt_F4_enabled
{
Send !{F4}
Alt_F4_enabled:= false
}
else
return ; do nothing
return
关于 #q
和 !F4::Return
:这些是 没有 命令,它们是热键,因此隐式包含 return
。您不能在可执行上下文中使用它。有关详细信息,请参阅下面的 http://ahkscript.org/docs/misc/Remap.htm#Remarks。
你不会想要在应该执行的行之间的某处有一个 return 吧。
(另见我的回答)
对于切换热键操作,我更喜欢使用 Hotkey
命令 (link):
hotkey, !F4, closeWindow, ON ; this is a command. "creates" a hotkey
closeWindow: ; this is a label
send !{f4}
return
#q:: ; this is a hotkey
hotkey, !F4, closeWindow, TOGGLE ; this is a command. disables or enables the hotkey
return
这样做,很容易动态地赋予!F4
更多的功能。
代码未测试
但事实上,没有什么大的理由不能以 user12344312257994344s 的方式做到这一点。
我正在尝试禁用 Alt + F4,但我想在按下 Windows 键 + Q 时启用它。到目前为止,我得到的这个不起作用。
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
if (#q)
{
Send !{F4}
Return
} else {
!F4::Return
}
; autoexecute section:
Alt_F4_enabled:= false
; ...
return ; end of autoexecute section
#q:: Alt_F4_enabled:= true
!F4::
If Alt_F4_enabled
{
Send !{F4}
Alt_F4_enabled:= false
}
else
return ; do nothing
return
关于 #q
和 !F4::Return
:这些是 没有 命令,它们是热键,因此隐式包含 return
。您不能在可执行上下文中使用它。有关详细信息,请参阅下面的 http://ahkscript.org/docs/misc/Remap.htm#Remarks。
你不会想要在应该执行的行之间的某处有一个 return 吧。
(另见我的回答
对于切换热键操作,我更喜欢使用 Hotkey
命令 (link):
hotkey, !F4, closeWindow, ON ; this is a command. "creates" a hotkey
closeWindow: ; this is a label
send !{f4}
return
#q:: ; this is a hotkey
hotkey, !F4, closeWindow, TOGGLE ; this is a command. disables or enables the hotkey
return
这样做,很容易动态地赋予!F4
更多的功能。
代码未测试
但事实上,没有什么大的理由不能以 user12344312257994344s 的方式做到这一点。