忽略所有热键 AutoHotKey
Ignore All Hotkeys AutoHotKey
代码
currentstring := ""
q::
ExitApp
return
w::
MsgBox,,,Hello`, World!,3
return
e::
MsgBox,,,Hello World,3
return
r::
InputBox, currentstring
*::
return
return
t::
MsgBox,,,%currentstring%,3
return
但是当我在 InputBox 中按下 q
、w
、e
、r
或 t
时,它会执行代码在 return 之前,即使我已经用 *::
覆盖了热键。
有什么办法解决这个问题吗?
*::
不是 "catch all" 热键,它只会在检测到星号(通常是 Shift+8)时触发。
要达到您想要的效果,您应该根据活动的热键激活 window。
工作示例
如果活动 window 是 InputBox
(ahk_class #32270
),禁用热键,但不要阻止它们的本机功能(~
前缀)。如果不是 InputBox
,请根据需要绑定热键。
#SingleInstance force
currentstring := ""
return ; end auto-execute section
#IfWinActive, ahk_class #32770 ; If an InputBox window, restore default key function
~q::
~w::
~e::
~r::
~t::
return
#IfWinActive ; If anything else
q::
ExitApp
return
w::
MsgBox,,,Hello`, World!,3
return
e::
MsgBox,,,Hello World,3
return
r::
InputBox, currentstring
return
t::
MsgBox,,,%currentstring%,3
return
备注:
- 最好的做法是只绑定您需要的热键,而不是绑定所有的热键。
- 要确定 Window 的属性(class、id 等),您可以使用 Active Window Info或与 AutoHotKey 捆绑在一起的 Window Spy 工具。如果未使用
Menu, Tray, NoStandard
,也可以从 运行 脚本的系统托盘图标启动它。
代码
currentstring := ""
q::
ExitApp
return
w::
MsgBox,,,Hello`, World!,3
return
e::
MsgBox,,,Hello World,3
return
r::
InputBox, currentstring
*::
return
return
t::
MsgBox,,,%currentstring%,3
return
但是当我在 InputBox 中按下 q
、w
、e
、r
或 t
时,它会执行代码在 return 之前,即使我已经用 *::
覆盖了热键。
有什么办法解决这个问题吗?
*::
不是 "catch all" 热键,它只会在检测到星号(通常是 Shift+8)时触发。
要达到您想要的效果,您应该根据活动的热键激活 window。
工作示例
如果活动 window 是 InputBox
(ahk_class #32270
),禁用热键,但不要阻止它们的本机功能(~
前缀)。如果不是 InputBox
,请根据需要绑定热键。
#SingleInstance force
currentstring := ""
return ; end auto-execute section
#IfWinActive, ahk_class #32770 ; If an InputBox window, restore default key function
~q::
~w::
~e::
~r::
~t::
return
#IfWinActive ; If anything else
q::
ExitApp
return
w::
MsgBox,,,Hello`, World!,3
return
e::
MsgBox,,,Hello World,3
return
r::
InputBox, currentstring
return
t::
MsgBox,,,%currentstring%,3
return
备注:
- 最好的做法是只绑定您需要的热键,而不是绑定所有的热键。
- 要确定 Window 的属性(class、id 等),您可以使用 Active Window Info或与 AutoHotKey 捆绑在一起的 Window Spy 工具。如果未使用
Menu, Tray, NoStandard
,也可以从 运行 脚本的系统托盘图标启动它。