Skip to content

Instantly share code, notes, and snippets.

@vicenteherrera
Last active October 21, 2020 16:21
Show Gist options
  • Save vicenteherrera/c89d9c4373387a60be5ff883cf514107 to your computer and use it in GitHub Desktop.
Save vicenteherrera/c89d9c4373387a60be5ff883cf514107 to your computer and use it in GitHub Desktop.
Autohotkey easier one handed keyboard
#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.
#SingleInstance
DetectHiddenWindows, On
; --- Small keyboard tweaks ---------------------------------------
; Inmediately send "~" for ALT+4 and ALTGr+4 without waiting for next letter
!4::Send {~}{space}
<^>!4::Send {~}{space}
; Send "$HOME/" for CTRL+4
^4::Send $HOME/
; Change to previous program, send up and enter, and change back
; Useful to retest code you are editing in the console
^w::
Send !{Tab}
sleep, 1000
Send {up}
Send {enter}
sleep, 500
Send !{Tab}
return
; --- Energy control and security ---------------------------------------
; Lock computer with Win + Q
; (I like it one handed and Win + L is too far away)
#q::
{
Sleep, 200
DllCall("LockWorkStation")
Sleep, 200
;SendMessage,0x112,0xF170,2,,Program Manager
}
; Turn off monitor with Win + M
#m::
Sleep 1000
SendMessage, 0x112, 0xF170, 2,, Program Manager
return
; Sleep computer with Win + 0
#0::
{
DllCall("PowrProf\SetSuspendState", "int", 0, "int", 0, "int", 0)
}
; --- Alternative navigate/copy/paste keyboard ---------------------------------
; Use Caps Lock as Scroll Lock
CapsLock::
Send, {ScrollLock}
ShowToolTip()
If (GetKeyState("ScrollLock", "T") = 0) {
SoundBeep
} else {
SoundBeep, 750, 100
}
return
; Show on screen Caps lock state
~$NumLock::
~$ScrollLock::
ShowToolTip()
return
ShowToolTip() {
send {%A_ThisHotkey% d}
KeyWait, %A_ThisHotkey%
NumState := GetKeyState("NumLock", "T")
CapsState := GetKeyState("CapsLock", "T")
ScrollState := GetKeyState("ScrollLock", "T")
If NumState = 1
NumState := "🟢"
If NumState = 0
NumState := "❌"
If CapsState = 1
CapsState := "UPPER"
If CapsState = 0
CapsState := "lower "
If ScrollState = 1
ScrollState := "🔼🔽"
If ScrollState = 0
ScrollState := "❌"
ToolTip, CAPS: %CapsState%`nNUM: %NumState%`nScroll: %ScrollState%
SetTimer, RemoveToolTip, 825
}
RemoveToolTip:
SetTimer, RemoveToolTip, Off
ToolTip
return
; Double shift = Caps Lock switch state
Shift::
if (A_ThisHotkey == A_PriorHotkey && A_TimeSincePriorHotkey <= 500)
{
SetCapsLockState % !GetKeyState("CapsLock", "T")
ShowToolTip()
SoundPlay, C:\Progs\Sounds\click.mp3
;SoundBeep, 450, 50
}
return
; When Scroll Lock is enabled, use AWSD keys for movement, zxcv for
sendIfScroll(lowerKey, upperKey, newKeyLower, newKeyUpper="", sound="") {
if GetKeyState("ScrollLock", "T") == 1 {
if (GetKeyState("CapsLock", "T") == 0 || newKeyLower=="") {
Send, %newKeyLower%
} else {
Send, %newKeyUpper%
}
SoundPlay, C:\Progs\Sounds\click.mp3
return
}
if GetKeyState("CapsLock", "T") == 1 {
Send, %upperKey%
} else {
Send, %lowerKey%
}
}
$w:: sendIfScroll("w","W", "{up}", "{up}", "")
$a:: sendIfScroll("a","A", "{left}", "{left}", "")
$s:: sendIfScroll("s","S", "{down}", "{down}", "")
$d:: sendIfScroll("d","D", "{right}", "{right}", "")
$q:: sendIfScroll("q","Q", "{enter}", "{enter}", "")
$c:: sendIfScroll("c","C", "^{c}", "^{c}", "C:\\Progs\\Sounds\\tap.mp3")
$x:: sendIfScroll("x","X", "^{x}", "^{x}", "C:\\Progs\\Sounds\\tap.mp3")
$z:: sendIfScroll("z","Z", "^{z}", "^{z}", "C:\\Progs\\Sounds\\tap.mp3")
$e:: sendIfScroll("e","E", "^{s}", "^{s}", "C:\\Progs\\Sounds\\tap.mp3")
$4:: sendIfScroll("4","4", "$", "$", "C:\\Progs\\Sounds\\tap.mp3")
$v:: sendIfScroll("v","V", "^v", "+^v", "C:\\Progs\\Sounds\\tap.mp3")
$+v:: sendIfScroll("V","v", "^v", "+^v", "C:\\Progs\\Sounds\\tap.mp3")
$Tab:: sendIfScroll("{Tab}","{Tab}","{Backspace}","{Backspace}","C:\\Progs\\Sounds\\tap.mp3")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment