Skip to content

Instantly share code, notes, and snippets.

@Danik
Last active April 15, 2024 11:34
Show Gist options
  • Star 98 You must be signed in to star a gist
  • Fork 32 You must be signed in to fork a gist
  • Save Danik/5808330 to your computer and use it in GitHub Desktop.
Save Danik/5808330 to your computer and use it in GitHub Desktop.
Autohotkey Capslock Remapping Script. Makes Capslock function as a modifier key to get cursor keys etc. on the left side of the keyboard, so you never have to move your hand to the right.
; Autohotkey Capslock Remapping Script
; Danik
; More info at http://danikgames.com/blog/?p=714
; danikgames.com
;
; Functionality:
; - Deactivates capslock for normal (accidental) use.
; - Hold Capslock and drag anywhere in a window to move it (not just the title bar).
; - Access the following functions when pressing Capslock:
; Cursor keys - J, K, L, I
; Enter - Space
; Home, PgDn, PgUp, End - U, O, Y, H
; Backspace and Del - N, M
;
; Insert - B
; Select all - A
; Cut, copy, paste - S, D, F
; Close tab, window - W, E
; Esc - R
; Next, previous tab - Tab, Q
; Undo, redo - , and .
; - Numpad at the right hand resting position when holding Ctrl+Shift+Alt (using keys m,.jkluio and spacebar)
;
; To use capslock as you normally would, you can press WinKey + Capslock
; This script is mostly assembled from modified versions of the following awesome scripts:
;
; # Home Row Computing by Gustavo Duarte: http://duartes.org/gustavo/blog/post/home-row-computing for
; Changes:
; - Does not need register remapping of AppsKey using SharpKeys.
; - Uses normal cursor key layout
; - Added more hotkeys for insert, undo, redo etc.
;
; # Get the Linux Alt+Window Drag Functionality in Windows: http://www.howtogeek.com/howto/windows-vista/get-the-linux-altwindow-drag-functionality-in-windows/
; Changes: The only change was using Capslock instead of Alt. This
; also removes problems in certain applications.
#Persistent
SetCapsLockState, AlwaysOff
; Capslock + jkli (left, down, up, right)
Capslock & j::Send {Blind}{Left DownTemp}
Capslock & j up::Send {Blind}{Left Up}
Capslock & k::Send {Blind}{Down DownTemp}
Capslock & k up::Send {Blind}{Down Up}
Capslock & i::Send {Blind}{Up DownTemp}
Capslock & i up::Send {Blind}{Up Up}
Capslock & l::Send {Blind}{Right DownTemp}
Capslock & l up::Send {Blind}{Right Up}
; Capslock + uohy (pgdown, pgup, home, end)
Capslock & u::SendInput {Blind}{Home Down}
Capslock & u up::SendInput {Blind}{Home Up}
Capslock & o::SendInput {Blind}{End Down}
Capslock & o up::SendInput {Blind}{End Up}
Capslock & y::SendInput {Blind}{PgUp Down}
Capslock & y up::SendInput {Blind}{PgUp Up}
Capslock & h::SendInput {Blind}{PgDn Down}
Capslock & h up::SendInput {Blind}{PgDn Up}
; Capslock + asdf (select all, cut-copy-paste)
Capslock & a::SendInput {Ctrl Down}{a Down}
Capslock & a up::SendInput {Ctrl Up}{a Up}
Capslock & s::SendInput {Ctrl Down}{x Down}
Capslock & s up::SendInput {Ctrl Up}{x Up}
Capslock & d::SendInput {Ctrl Down}{c Down}
Capslock & d up::SendInput {Ctrl Up}{c Up}
Capslock & f::SendInput {Ctrl Down}{v Down}
Capslock & f up::SendInput {Ctrl Up}{v Up}
; Capslock + wer (close tab or window, press esc)
Capslock & w::SendInput {Ctrl down}{F4}{Ctrl up}
Capslock & e::SendInput {Alt down}{F4}{Alt up}
Capslock & r::SendInput {Blind}{Esc Down}
; Capslock + nm (insert, backspace, del)
Capslock & b::SendInput {Blind}{Insert Down}
Capslock & m::SendInput {Blind}{Del Down}
Capslock & n::SendInput {Blind}{BS Down}
Capslock & BS::SendInput {Blind}{BS Down}
; Make Capslock & Enter equivalent to Control+Enter
Capslock & Enter::SendInput {Ctrl down}{Enter}{Ctrl up}
; Make Capslock & Alt Equivalent to Control+Alt
!Capslock::SendInput {Ctrl down}{Alt Down}
!Capslock up::SendInput {Ctrl up}{Alt up}
; Capslock + TAB/q (prev/next tab)
Capslock & q::SendInput {Ctrl Down}{Tab Down}
Capslock & q up::SendInput {Ctrl Up}{Tab Up}
Capslock & Tab::SendInput {Ctrl Down}{Shift Down}{Tab Down}
Capslock & Tab up::SendInput {Ctrl Up}{Shift Up}{Tab Up}
; Capslock + ,/. (undo/redo)
Capslock & ,::SendInput {Ctrl Down}{z Down}
Capslock & , up::SendInput {Ctrl Up}{z Up}
Capslock & .::SendInput {Ctrl Down}{y Down}
Capslock & . up::SendInput {Ctrl Up}{y Up}
; Make Capslock+Space -> Enter
Capslock & Space::SendInput {Enter Down}
; Numpad using Ctrl+Shift+Alt + m,.jkluio or space
+^!Space:: SendInput {Numpad0}
+^!m:: SendInput {Numpad1}
+^!,:: SendInput {Numpad2}
+^!.:: SendInput {Numpad3}
+^!j:: SendInput {Numpad4}
+^!k:: SendInput {Numpad5}
+^!l:: SendInput {Numpad6}
+^!u:: SendInput {Numpad7}
+^!i:: SendInput {Numpad8}
+^!o:: SendInput {Numpad9}
; Make Win Key + Capslock work like Capslock (in case it's ever needed)
#Capslock::
If GetKeyState("CapsLock", "T") = 1
SetCapsLockState, AlwaysOff
Else
SetCapsLockState, AlwaysOn
Return
; Drag windows anywhere
;
; This script modified from the original: http://www.autohotkey.com/docs/scripts/EasyWindowDrag.htm
; by The How-To Geek
; http://www.howtogeek.com
Capslock & LButton::
CoordMode, Mouse ; Switch to screen/absolute coordinates.
MouseGetPos, EWD_MouseStartX, EWD_MouseStartY, EWD_MouseWin
WinGetPos, EWD_OriginalPosX, EWD_OriginalPosY,,, ahk_id %EWD_MouseWin%
WinGet, EWD_WinState, MinMax, ahk_id %EWD_MouseWin%
if EWD_WinState = 0 ; Only if the window isn't maximized
SetTimer, EWD_WatchMouse, 10 ; Track the mouse as the user drags it.
return
EWD_WatchMouse:
GetKeyState, EWD_LButtonState, LButton, P
if EWD_LButtonState = U ; Button has been released, so drag is complete.
{
SetTimer, EWD_WatchMouse, off
return
}
GetKeyState, EWD_EscapeState, Escape, P
if EWD_EscapeState = D ; Escape has been pressed, so drag is cancelled.
{
SetTimer, EWD_WatchMouse, off
WinMove, ahk_id %EWD_MouseWin%,, %EWD_OriginalPosX%, %EWD_OriginalPosY%
return
}
; Otherwise, reposition the window to match the change in mouse coordinates
; caused by the user having dragged the mouse:
CoordMode, Mouse
MouseGetPos, EWD_MouseX, EWD_MouseY
WinGetPos, EWD_WinX, EWD_WinY,,, ahk_id %EWD_MouseWin%
SetWinDelay, -1 ; Makes the below move faster/smoother.
WinMove, ahk_id %EWD_MouseWin%,, EWD_WinX + EWD_MouseX - EWD_MouseStartX, EWD_WinY + EWD_MouseY - EWD_MouseStartY
EWD_MouseStartX := EWD_MouseX ; Update for the next timer-call to this subroutine.
EWD_MouseStartY := EWD_MouseY
return
@jeffreysbrother
Copy link

Do you know of a way to add a script like this as a startup item in Windows 10?

@Tobl4
Copy link

Tobl4 commented Apr 14, 2016

@jeffreysbrother If you have ahk installed, you can compile the script via the context menu and then set up the resulting .exe to autostart like any other program.

@UniversalCorn
Copy link

Good job. Thanks.

@emshan
Copy link

emshan commented Apr 10, 2018

I was using xmodmap for linux and have been trying to find a solution. Works like a charm. Thanks.

@yderi
Copy link

yderi commented Jul 2, 2019

Hi, thanks for the script
How can we add F1 -F12 via Capslock+1,2,3 and so on?
Actually, I've tried to add the following section:
; Capslock + 1234567890-= (F1-F12) Capslock & 1::Send {F1} Capslock & 2::Send {F2} Capslock & 3::Send {F3} Capslock & 4::Send {F4} Capslock & 5::Send {F5} Capslock & 6::Send {F6} Capslock & 7::Send {F7} Capslock & 8::Send {F8} Capslock & 9::Send {F9} Capslock & 0::Send {F10} Capslock & -::Send {F11} Capslock & =::Send {F12}
But if I want to use in conjuction with ALT (for example to send Alt+F4) it only sends a F4 function, and doesnt pay to Alt pressed.

@wayanlw
Copy link

wayanlw commented May 23, 2020

Works great. Thanks for sharing. Was trying to map to map LAlt to LCtrl when CapsLock is pressed, coz LAlt is at a more convenient place than LCtrl and I use Ctrl more often. Eg. LAlt+Capslock+J to LCtrl+LeftArrow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment