Skip to content

Instantly share code, notes, and snippets.

@inxomnyaa
Created May 8, 2025 02:05
Show Gist options
  • Save inxomnyaa/33b3c87377d874cbd6b1ec1531d55198 to your computer and use it in GitHub Desktop.
Save inxomnyaa/33b3c87377d874cbd6b1ec1531d55198 to your computer and use it in GitHub Desktop.
Cycle the CASE of selected text like on Android via CAPS - AutoHotkey v2
;AHKv2
#SingleInstance Force
#Warn
CapsLock:: {
static state := 0
static originalText := ""
clipboardBackup := A_Clipboard
A_Clipboard := "" ; Clear clipboard
Send("^c")
if !ClipWait(0.1) || A_Clipboard = "" {
A_Clipboard := clipboardBackup
Send("{CapsLock}")
return
}
currentText := A_Clipboard
; Reset state if selected text has changed
if (currentText != originalText) {
originalText := currentText
state := 0
}
; Apply transformation
if (state = 0) {
newText := StrUpper(originalText)
state := 1
}
else if (state = 1) {
newText := RegExReplace(StrLower(originalText), "\b\w", "$U0")
state := 2
}
else if (state = 2) {
newText := StrLower(originalText)
state := 3
}
else {
newText := originalText
state := 0
}
A_Clipboard := newText
Send("^v")
Sleep(50)
; Reselect the pasted text
Send("{Shift Down}")
Loop StrLen(newText) {
Send("{Left}")
}
Send("{Shift Up}")
A_Clipboard := clipboardBackup
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment