首页 > 解决方案 > 执行 winkey 后任何可能的热键组合的任务

问题描述

我希望以 LWin 开头的任何可能的键序列来执行特定任务,例如:

LWin & a::
;Execute the task

或者:

LWin & b::
;Execute the task

等等...

当然,对于所有键盘键,写这个是不可能的,所以我想到了这样的东西:

LWin & *::     ; * = KEY
KEY = %A_ThisHotkey%    ; KEY is now = LWin & a (for example)
KEY := RegExReplace(Clipboard,"i)^lwIN & ")    ; KEY is now = a
; The task that needs to be executed:
Send {LWin UP}
Send {%KEY% DOWN}
KeyWait %KEY%
Send {%KEY% up}
return

但问题是,不能这样使用通配符。如何做到这一点?

标签: autohotkey

解决方案


*LWin::
    Input, key, L1
    if (ErrorLevel = "NewInput")
        Send, {LWin}      ; LWin was pressed alone: pass-thru
    else if (IsLabel(key))
        Goto, % key
    else
        Send, % "#" key   ; pass-thru
return
*LWin UP::Input           ; stop listening for secondary key

; Tasks defined here
s:
    MsgBox, "s" task launched!
return
p:
    MsgBox, "p" task launched!
return

推荐阅读