Skip to content

Instantly share code, notes, and snippets.

@b-
Created July 25, 2019 18:24
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 b-/d7f91bd7489d1b515161ebd5c5cab25a to your computer and use it in GitHub Desktop.
Save b-/d7f91bd7489d1b515161ebd5c5cab25a to your computer and use it in GitHub Desktop.
; br's personal ahk keyboard remappings
; https://github.com/b-/keyboard-customizer
; Released into the Public Domain via CC0 https://creativecommons.org/share-your-work/public-domain/cc0/
;;;;;
; Run as administrator (the scheduled task included will do so on startup) for this to work on applications also running as administrator.
; Otherwise, the keyboard mappings will simply not work.
#SingleInstance Force
#InstallKeybdHook
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
; Synergy stuff
script:=
(
loop
{
if WinActive("ahk_class SynergyDesk")
{
; We want to reload ONCE
EnvGet, IsReloading, IsReloading
if ( IsReloading = "true" ) ; we're already reloading
{
EnvSet, IsReloading, "false"
WinWaitNotActive, ahk_class SynergyDesk
} ; so don't reload again
else
{
EnvSet, IsReloading, "true"
}
}
}
)
;;;;;;;;;;;;;functions;;;;;;;;;;;;
; ExecScript: Executes the given code as a new AutoHotkey process.
ExecScript(Script, Wait:=false)
{
shell := ComObjCreate("WScript.Shell")
exec := shell.Exec("AutoHotkey.exe /ErrorStdOut *")
exec.StdIn.Write(script)
exec.StdIn.Close()
if Wait
return exec.StdOut.ReadAll()
}
; Set the caps lock state
; The keyboard I'm coding this on doesn't have a capslock LED. Don't ask me why; it's a stupid laptop.
; Therefore I am using the tray icon as one.
if (state = 0) {
SetCapsLockState, alwaysoff ; Caps has to either be "alwaysoff" or "alwayson" because of the mappings involving it.
Menu, Tray, Icon, %A_WorkingDir%/caps-off.png
Menu, Tray, Tip, Key Customizer (caps off)
}
else if (state = 1) {
SetCapsLockState, alwayson ; Caps has to either be "alwaysoff" or "alwayson" because of the mappings involving it
Menu, Tray, Icon, %A_WorkingDir%/caps-on.png
Menu, Tray, Tip, Key Customizer (CAPS ON)
}
}
ToggleCaps() {
; Toggle caps lock
; This function is because we cannot simply send a Capslock keypress to reliably toggle the capslock state, due to remapping the key.
if (GetKeyState("Capslock", "T") = 1) { ; if caps lock is on
SetCaps(0) ; turn it off
} else if (GetKeyState("Capslock", "T") = 0) ; else if caps lock is off
{
SetCaps(1) ; turn it on
}
}
;;;;;;;;;;;;;;
; Turn off Caps on start: I can't seem to reliably get the state of caps lock upon program start, so I'm just manually setting it to off
SetCaps(0)
;tab/arrow settings
*Tab::Send {Blind}{Tab} ; Send tab explicitly when no other key is pressed before letting go, including any modifiers being held
#If GetKeyState("Tab", "p") ; Autohotkey_L directive for enabling following mappings when key is physically down
h::Left
l::Right
Tab & F1::Return ;workaround for strange bug regarding "up". Apparently it's in some documentation?
k::Up
j::Down
#If ;endif
*Capslock::
Send {LControl Down}
sendEsc := true ; initialize it as true.
KeyWait, CapsLock, T0.25 ; Wait for CapsLock to be released. timeout after 250ms
if ( ErrorLevel >= 1) ; ErrorLevel = 1 if timeout. That is, if we never released caps
{
sendEsc := false ; if we don't release caps quickly, we shouldn't press once we finally release it.
}
KeyWait, CapsLock ; We still need to wait for the key to be released; KeyWait is synchronous, so the program pauses while we do this.
Send {LControl Up}
if ( A_PriorKey = "CapsLock" ) && ( sendEsc == true ) ; if we never pressed another key AND if we didn't set sendEsc to false by timing out
{
Send {Esc} ; only then do we send esc.
}
return
LShift & RShift::ToggleCaps() ; Toggle caps on
RShift & LShift::ToggleCaps() ; Need to program both orders of shift keys for this to work properly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment