AHK 击键仅在按下时显示图像

AHK keystroke to show image only while it's pressed

美好的一天,

我正在尝试为 AutoHotKey (AHK) 创建一个脚本,它会在按下 Caps lock+A 时显示图像同时释放按键后隐藏

我当前的解决方案显示图像,但只有在按 Esc 后它才会消失:

#Persistent
SetCapsLockState, AlwaysOff
#If, GetKeyState("CapsLock", "P")

a::
Gui +LastFound +AlwaysOnTop +ToolWindow -Theme -Border -Caption
Gui, Color, FFFFFF
WinSet, Transcolor, FFFFFF
Gui, Add, Picture, x0 y0 w1827 h635, C:\Users\User\Image.png
Gui, Show, xCenter y360 w1827 h635
Gui, Margin, 0,0
return
GuiEscape: 
Gui, Cancel
Gui, Hide
return

我试过设置 statea UP:: 但没有任何效果。期待一些帮助。

KeyWait 看来是你要找的。

来自文档:

KeyWait

Waits for a key or mouse/joystick button to be released or pressed down.

KeyWait, KeyName , Options

所以为了延迟脚本直到 a 键被释放,你可以这样实现它:

KeyWait a

最终代码:

SetCapsLockState, AlwaysOff
#If, GetKeyState("CapsLock", "P")

a::
Gui +LastFound +AlwaysOnTop +ToolWindow -Theme -Border -Caption
Gui, Color, FFFFFF
WinSet, Transcolor, FFFFFF
Gui, Add, Picture, x0 y0 w1827 h635, C:\Users\User\Image.png
Gui, Show, xCenter y360 w1827 h635
Gui, Margin, 0,0
KeyWait a
gosub GuiEscape
return

GuiEscape: 
Gui, Cancel
Gui, Hide
return