Skip to content

Instantly share code, notes, and snippets.

@Pandahisham
Created December 4, 2015 13:35
Show Gist options
  • Save Pandahisham/e66556d6df014dc08540 to your computer and use it in GitHub Desktop.
Save Pandahisham/e66556d6df014dc08540 to your computer and use it in GitHub Desktop.
cycle changing
;-Change Text Case-----------------------------------------
cycleNumber := 1
#IfWinNotActive ahk_class XLMAIN
^t::
If (cycleNumber==1)
{
ConvertUpper()
cycleNumber:= 2
}
Else If (cycleNumber==2)
{
ConvertLower()
cycleNumber:= 3
}
Else If (cycleNumber==3)
{
ConvertTitleCase()
cycleNumber:= 4
}
Else
{
ConvertSentence()
cycleNumber:= 1
}
Return
ConvertUpper()
{
clipSave := Clipboard
Clipboard = ; Empty the clipboard so that ClipWait has something to detect
SendInput, ^c ;copies selected text
ClipWait
StringReplace, Clipboard, Clipboard, `r`n, `n, All ;Fix for SendInput sending Windows linebreaks
StringUpper, Clipboard, Clipboard
Len:= Strlen(Clipboard)
SendInput, ^v ;pastes new text
Send +{left %Len%}
Clipboard := clipSave
}
ConvertLower()
{
clipSave := Clipboard
Clipboard = ; Empty the clipboard so that ClipWait has something to detect
SendInput, ^c ;copies selected text
ClipWait
StringReplace, Clipboard, Clipboard, `r`n, `n, All ;Fix for SendInput sending Windows linebreaks
StringLower, Clipboard, Clipboard
Len:= Strlen(Clipboard)
SendInput, ^v ;pastes new text
Send +{left %Len%}
Clipboard := clipSave
}
ConvertTitleCase()
{
clipSave := Clipboard
Clipboard = ; Empty the clipboard so that ClipWait has something to detect
SendInput, ^c ;copies selected text
ClipWait
StringReplace, Clipboard, Clipboard, `r`n, `n, All ;Fix for SendInput sending Windows linebreaks
StringLower, Clipboard, Clipboard, T
Len:= Strlen(Clipboard)
SendInput, ^v ;pastes new text
Send +{left %Len%}
Clipboard := clipSave
}
ConvertSentence()
{
clipSave := Clipboard
Clipboard = ; Empty the clipboard so that ClipWait has something to detect
SendInput, ^c ;copies selected text
ClipWait
StringReplace, Clipboard, Clipboard, `r`n, `n, All ;Fix for SendInput sending Windows linebreaks
StringLower, Clipboard, Clipboard
Clipboard := RegExReplace(Clipboard, "(((^|([.!?]+\s+))[a-z])| i | i')", "$u1")
Len:= Strlen(Clipboard)
SendInput, ^v ;pastes new text
Send +{left %Len%}
VarSetCapacity(OutputText, 0) ;free memory
Clipboard := clipSave
}
#IfWinNotActive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment