Skip to content

Instantly share code, notes, and snippets.

@fabiolib
Forked from Danik/capslock_remap_alt.ahk
Last active July 1, 2020 15:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fabiolib/867b76f0355a2b139601756a74828201 to your computer and use it in GitHub Desktop.
Save fabiolib/867b76f0355a2b139601756a74828201 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. Added Alt-Tab function to mouse buttons.
; 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
;
; Close tab - W
; New window - D
; New tab - Q
; Next, previous tab - S, A
; Undo, redo - Z and X
;
; - 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 + w,d,q (close tab, new window, new tab)
Capslock & w::SendInput {Ctrl down}{F4}{Ctrl up}
Capslock & d::SendInput {Ctrl down}{n}{Ctrl up}
Capslock & q::SendInput {Ctrl down}{t}{Ctrl up}
; 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 + a/s (prev/next tab)
Capslock & s::SendInput {Ctrl Down}{Tab Down}
Capslock & s up::SendInput {Ctrl Up}{Tab Up}
Capslock & a::SendInput {Ctrl Down}{Shift Down}{Tab Down}
Capslock & a up::SendInput {Ctrl Up}{Shift Up}{Tab Up}
; Capslock + z/x (undo/redo)
Capslock & z::SendInput {Ctrl Down}{z Down}
Capslock & z up::SendInput {Ctrl Up}{z Up}
Capslock & x::SendInput {Ctrl Down}{y Down}
Capslock & x 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
;>>>>Mouse Controlz<<<
;https://autohotkey.com/board/topic/4235-leos-5-button-mouse-control/
XButton1 & LButton::WinMinimize A ;minimizes windows
XButton1 & RButton::Send, #d ;shows desktop
;Alt-Tab Replacement
;https://stackoverflow.com/questions/48651443/autohotkey-issue-with-alt-tab-shortcut
XButton2::
AltTabMenu := true ; assign the Boolean value "true" or "1" to this variable
Send, {Alt down}{Tab}
return
; The #If directive creates context-sensitive hotkeys:
#If (AltTabMenu) ; If this variable has the value "true"
; The * prefix fires the hotkey even if extra modifiers (in this case Alt) are being held down
*Enter::
*RButton::
Send {Enter}
Send {Blind}{Alt Up} ; release Alt
MouseCenterInActiveWindow()
AltTabMenu := false
return
*XButton2::
Send {Blind}{Alt Up} ; release Alt
AltTabMenu := false
return
~*LButton::
Click
Send {Blind}{Alt Up} ; release Alt
MouseCenterInActiveWindow()
AltTabMenu := false
return
; menu navigation by scrolling the mouse wheel:
*WheelUp:: Send {Right}
*WheelDown:: Send {Left}
#If ; turn off context sensitivity
MouseCenterInActiveWindow(){
WinGetPos,,Y, Width, Height, A ; get active window size
Xcenter := Width/2 ; calculate center of active window
Ycenter := Height/2
MouseMove, Xcenter, Ycenter, 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment