12

I'm migrating my mac workflow to Windows. One thing I couldn't live without is hyper key which is combination of Ctrl + Option + Shift + Cmd. I use Karabiner app to remap Capslock to this Hyper key. I have heard that Autohotkey is an Karabiner alternative for Windows. Could you guys please help me to emulate this feature in Windows.

My ideal result is:

  • Deactivate Capslock completely because I rarely use this
  • Toggle Capslock will perform ESC key
  • Hold down Capslock will perform Ctrl + Alt + Shift + Windows. For example Capslock + C will be Ctrl+Alt+Shift+Windows+C

Many thanks in advance!

The following is my attempt with ahk script but it doesn't work at all :(

;-----------------------------------------
; 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
babygau
  • 1,551
  • 18
  • 27
  • Not a programming question - try [su] ? – Paul R Nov 05 '16 at 07:52
  • @PaulR tks for pointing me to that website. I'll post the same question though I thought **Autohotkey script** is also a type of programming language. – babygau Nov 05 '16 at 07:55
  • 1
    I guess it might be a programming question if you had tried to write an Autohotkey script and it wasn't working, in which case you'd post the non-working script here and ask for help fixing it. But as it stands the question reads more like a general user-level problem, i.e. "how do I do X with software Y ?". – Paul R Nov 05 '16 at 08:00
  • @PaulR you're right. As I'm reading through Autohotkey docs, hope that I could produce sth by tmr. I'm asking the question in the hope of some Autohotkey guru could give me a quick answer. – babygau Nov 05 '16 at 08:08
  • @babygau Your question is too broad. SO is not a code writing service. Present a *specific* problem you're having with code and we can help you solve that problem. – 2501 Nov 05 '16 at 12:08
  • @2501pls see my updated code snippet, it didn't work when I used all key bindings above. – babygau Nov 06 '16 at 06:41

3 Answers3

26

Thanks for anyone trying to help me, I figured out the prob on my own and would like to share it in case anyone comes across this prob.

#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}
babygau
  • 1,551
  • 18
  • 27
  • the only answer I found on Capslock hyper on Windows using Autohotkey. Thanks @babygau!! – snowbound Mar 26 '17 at 01:32
  • INSANE. Thanks a lot! This needs more upvotes. VIM guy here as well so that's a bonus. I use the same combos. – Vik Jul 14 '17 at 06:03
  • 1
    Also see this for disabling the launch of office for the hyper key: https://superuser.com/questions/1455857/how-to-disable-office-key-keyboard-shortcut-opening-office-app – Amir T Jul 11 '20 at 21:38
2

You can use one attache to Karabiner here: https://github.com/Vonng/Capslock/blob/master/win/CapsLock.ahk

which maps the same hot keys you are used to using on your 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                            |

To install it do as follows from doc:

  1. Right-Click on your desktop.
  2. Find "New" in the menu.
  3. Click "AutoHotkey Script" inside the "New" menu.
  4. Give the script a new name. It must end with a .ahk extension. For example: MyScript.ahk
  5. Find the newly created file on your desktop and right-click it.
  6. Click "Edit Script".
  7. A window should have popped up, probably Notepad. If so, SUCCESS!
  8. Save the File.
  9. Double-click the file/icon in the desktop to run it. Open notepad or (anything you can type in) and press Ctrl and J.
  10. Hip Hip Hooray! Your first script is done. Go get some reward snacks then return to reading the rest of this tutorial.
J.Wincewicz
  • 849
  • 12
  • 19
0

An updated version of @babygau's script for AutoHotkey v2 that I just finished sorting out, in case it helps anyone :)

#Requires AutoHotkey v2.0
; recommended for performance and compatibility with future autohotkey releases.
#UseHook
#SingleInstance force

InstallKeybdHook()

SendMode "Input"

;; deactivate capslock completely
SetCapslockState("AlwaysOff")

global CapslockIsDown := false

SetTimer(HandleCapslock, 50)

HandleCapslock() {
    global CapslockIsDown

    if (!CapslockIsDown && GetKeyState("Capslock", "P")) {
        CapslockIsDown := true
        Send("{Ctrl DownTemp}{Shift DownTemp}{Alt DownTemp}{LWin DownTemp}")
    } else if (CapslockIsDown && !GetKeyState("Capslock", "P")) {
        CapslockIsDown := false
        Send("{Ctrl Up}{Shift Up}{Alt Up}{LWin Up}")
        if (A_PriorKey == "Capslock") {
            Send("{Esc}")
        }
    }
}

;; vim navigation with hyper
Hotkey "~Capslock & h", SendLeft
Hotkey "~Capslock & l", SendRight
Hotkey "~Capslock & k", SendUp
Hotkey "~Capslock & j", SendDown

SendLeft(ThisHotkey) {
    Send("{Left}")
}

SendRight(ThisHotkey) {
    Send("{Right}")
}

SendUp(ThisHotkey) {
    Send("{Up}")
}

SendDown(ThisHotkey) {
    Send("{Down}")
}

;; popular hotkeys with hyper
Hotkey "~Capslock & c", SendCtrlC
Hotkey "~Capslock & v", SendCtrlV
SendCtrlC(ThisHotkey) {
    Send("^c")
}

SendCtrlV(ThisHotkey) {
    Send("^v")
}
D_Liver
  • 25
  • 4