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

时间:2016-11-05 07:50:15

标签: windows autohotkey

我正在将我的mac工作流迁移到Windows。我不能没有的一件事是超级密钥,它是Ctrl + Option + Shift + Cmd的组合。我使用 Karabiner 应用将Capslock重新映射到此Hyper密钥。我听说 Autohotkey 是Windows的 Karabiner替代品。你能帮助我在Windows中模仿这个功能吗?

我理想的结果是:

  • 完全取消Capslock,因为我很少使用此
  • 切换Capslock将执行ESC密钥
  • 按住Capslock将执行Ctrl + Alt + Shift + Windows。例如,Capslock + C将为Ctrl+Alt+Shift+Windows+C

非常感谢提前!

以下是我使用ahk脚本的尝试,但它根本不起作用:(

;-----------------------------------------
; 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
Capslock::
SendInput {Blind}{Ctrl Down}{Alt Down}{Shift Down}{LWin Down}
return

Capslock up::
SendInput {Blind}{Ctrl Up}{Alt Up}{Shift Up}{LWin Up}
return

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

;; popular hotkeys with hyper
^!+#c::^c
^!+#v::^v

2 个答案:

答案 0 :(得分:14)

感谢任何想要帮助我的人,我自己想出了这个问题,并且想要分享它以防万一有人遇到这个问题。

#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 https://autohotkey.com/docs/commands/Send.htm, 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}

答案 1 :(得分:0)

您可以在此处使用一名 Karabiner 专员: https://github.com/Vonng/Capslock/blob/master/win/CapsLock.ahk

映射您在 Mac 上使用的相同热键

;Summary:                                                             |
;o----------------------o---------------------------------------------o
;|CapsLock;             | {ESC}  Especially Convient for vim user     |
;|CaspLock + `          | {CapsLock}CapsLock Switcher as a Substituent|
;|CapsLock + hjklwb     | Vim-Style Cursor Mover                      |
;|CaspLock + uiop       | Convient Home/End PageUp/PageDn             |
;|CaspLock + nm,.       | Convient Delete Controller                  |
;|CapsLock + zxcvay     | Windows-Style Editor                        |
;|CapsLock + Direction  | Mouse Move                                  |
;|CapsLock + Enter      | Mouse Click                                 |
;|CaspLock + {F1}~{F6}  | Media Volume Controller                     |
;|CapsLock + qs         | Windows & Tags Control                      |
;|CapsLock + ;'[]       | Convient Key Mapping                        |
;|CaspLock + dfert      | Frequently Used Programs (Self Defined)     |
;|CaspLock + 123456     | Dev-Hotkey for Visual Studio (Self Defined) |
;|CapsLock + 67890-=    | Shifter as Shift                            |

要安装它,请从 doc 执行以下操作:

  1. 右键单击您的桌面。
  2. 在菜单中找到“新建”。
  3. 点击“新建”菜单中的“AutoHotkey Script”。
  4. 为脚本指定一个新名称。它必须以 .ahk 扩展名结尾。例如:MyScript.ahk
  5. 在桌面上找到新创建的文件并右键单击它。
  6. 点击“编辑脚本”。
  7. 应该会弹出一个窗口,可能是记事本。如果是这样,那么成功!
  8. 保存文件。
  9. 双击桌面上的文件/图标来运行它。打开记事本或(您可以输入的任何内容)并按 CtrlJ
  10. 嘻哈嘻哈万岁!您的第一个脚本已完成。去获取一些奖励零食,然后返回阅读本教程的其余部分。