From 98beb00ec2c0fea609c1c7f06f74c8534480ade9 Mon Sep 17 00:00:00 2001 From: Nathan Steel Date: Wed, 11 Aug 2021 15:23:56 +0100 Subject: [PATCH] Add autohotkey Caps rebind - Add an autohotkey keybind for caps lock. - Caps alone is Esc, Caps with another key in a CTRL modifier --- autohotkey/README.md | 7 +++++ autohotkey/caps_bind.ahk | 58 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 autohotkey/README.md create mode 100755 autohotkey/caps_bind.ahk diff --git a/autohotkey/README.md b/autohotkey/README.md new file mode 100644 index 0000000..b63bb6c --- /dev/null +++ b/autohotkey/README.md @@ -0,0 +1,7 @@ +Autohotkey is the way to rebind keys, and set macros in Windows. + +To make your scripts work on Windows load add them to your startup directory. + +Press `Windows + R` +Type `shell:startup` and hit `Enter` +Drop your scripts into there diff --git a/autohotkey/caps_bind.ahk b/autohotkey/caps_bind.ahk new file mode 100755 index 0000000..53cbe06 --- /dev/null +++ b/autohotkey/caps_bind.ahk @@ -0,0 +1,58 @@ +; Caps press is Escape +; Caps held with another key is CTRL +#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. +; #Warn ; Enable warnings to assist with detecting common errors. +SendMode Input ; Recommended for new scripts due to its superior speed and reliability. +;SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory. + +SetCapsLockState Off +state:=false +Esc:: + state:= not state + if (state) { + SetCapsLockState On + } else { + SetCapsLockState Off + } + Return + +*CapsLock:: + Send {LControl down} + Return +*CapsLock up:: + Send {LControl Up} + if (A_PriorKey=="CapsLock"){ + if (A_TimeSincePriorHotkey < 1000) + Suspend On + Send, {Esc} + Suspend Off + } + Return +; The next part is only relevant to users of Virtual Box, which interacts weirdly with AutoHotkey. The code below resets ctrl and caps lock when a Virtual Box window is unfocused. +InVB() +{ + return WinActive("ahk_exe VirtualBox.exe") +} +in_vb:=InVB() +was_in_vb:=in_vb + +Gui +LastFound +hWnd := WinExist() +DllCall( "RegisterShellHookWindow", UInt,Hwnd ) +MsgNum := DllCall( "RegisterWindowMessage", Str,"SHELLHOOK" ) +OnMessage( MsgNum, "ShellMessage" ) + +ShellMessage( wParam,lParam ) +{ + global in_vb + global was_in_vb + was_in_vb:=in_vb + in_vb:=InVB() + if (was_in_vb and not in_vb) + { + Suspend On + Send {LControl Up} + SetCapsLockState Off + Suspend Off + } +}