如何使用 autohotkey 在 Windows 10 中模拟超级键

如何使用 autohotkey 在 Windows 10 中模拟超级键

我正在将我的 Mac 工作流程迁移到 Windows。有一件事我不能没有,那就是超级键,它是Ctrl+ Option+ Shift+的组合Cmd。我使用登山扣应用程序重新映射Capslock到此Hyper键。我听说自动热键是一个Windows 的 Karabiner 替代品。你们能帮我在 Windows 中模拟这个功能吗?

我的理想结果是:

  • 完全停用Capslock,因为我很少使用它
  • 切换Capslock将执行ESC
  • 按住Capslock将执行Ctrl+ Alt+ Shift+ Windows。例如Capslock + C将是Ctrl+Alt+Shift+Windows+C

提前谢谢了!

为了解决我的问题,我写了几行代码,但根本不起作用。请帮我指出我的错误:

;-----------------------------------------
; hyper key for windows
;=========================================

; --------------------------------------------------------------
; notes
; --------------------------------------------------------------
; ! = alt
; ^ = ctrl
; + = shift
; # = lwin|rwin
;
#NoEnv ; recommended for performance and compatibility with future autohotkey releases.
#UseHook
#InstallKeybdHook
#SingleInstance force

SendMode Input

;; deactivate capslock completely
SetCapslockState, AlwaysOff

;; remap capslock to hyper
;; if capslock is toggled, remap it to esc

Capslock::
    SendInput {Ctrl Down}{Alt Down}{Shift Down}{LWin Down}
    KeyWait, Capslock
    SendInput {Ctrl Up}{Alt Up}{Shift Up}{LWin Up}
    if (A_PriorKey = "Capslock") {
        SendInput {Esc}
    }
return

;; vim navigation with hyper
~^!+#h:: SendInput {Left}
~^!+#l:: SendInput {Right}
~^!+#k:: SendInput {Up}
~^!+#j:: SendInput {Down}

;; popular hotkeys with hyper
~^!+<#c:: SendInput ^{c}
~^!+<#v:: SendInput ^{v}

结果:

  • 切换 Capslock 执行 ESC
  • 按住 Capslock 可执行 Ctrl+Alt+Shift+Win 组合键
  • 按住 Ctrl+Alt+Shift+Win 并按 h、j、k、l、c、v 键即可正常运行
  • 然而按住 Capslock 和 h、j、k、l、c、v 不起作用

答案1

感谢任何试图帮助我的人,我自己解决了这个问题,并愿意与大家分享,以防有人遇到这个问题。

#NoEnv ; recommended for performance and compatibility with future autohotkey releases.
#UseHook
#InstallKeybdHook
#SingleInstance force

SendMode Input

;; deactivate capslock completely
SetCapslockState, AlwaysOff

;; remap capslock to hyper
;; if capslock is toggled, remap it to esc

;; note: must use tidle prefix to fire hotkey once it is pressed
;; not until the hotkey is released
~Capslock::
    ;; must use downtemp to emulate hyper key, you cannot use down in this case 
    ;; according to http://bit.ly/2fLyHHI, downtemp is as same as down except for ctrl/alt/shift/win keys
    ;; in those cases, downtemp tells subsequent sends that the key is not permanently down, and may be 
    ;; released whenever a keystroke calls for it.
    ;; for example, Send {Ctrl Downtemp} followed later by Send {Left} would produce a normal {Left}
    ;; keystroke, not a Ctrl{Left} keystroke
    Send {Ctrl DownTemp}{Shift DownTemp}{Alt DownTemp}{LWin DownTemp}
    KeyWait, Capslock
    Send {Ctrl Up}{Shift Up}{Alt Up}{LWin Up}
    if (A_PriorKey = "Capslock") {
        Send {Esc}
    }
return

;; vim navigation with hyper
~Capslock & h:: Send {Left}
~Capslock & l:: Send {Right}
~Capslock & k:: Send {Up}
~Capslock & j:: Send {Down}

;; popular hotkeys with hyper
~Capslock & c:: Send ^{c}
~Capslock & v:: Send ^{v}

相关内容