The script below is in AutoHotkey v2 and uses a pop up menu that allows you to select the type of case you want the text to be changed to.
It should work with special characters such as é and â (unicode compatible). See TestString below for a more comprehensive example.
Code: Select all
#Requires AutoHotkey v2.0
!c:: { ; ALT + C
CaseChangeMenu := Menu()
CaseChangeMenu.Delete
CaseChangeMenu.Add("&1 lower case",ConvertLower)
CaseChangeMenu.Add("&2 Sentence case",ConvertSentence)
CaseChangeMenu.Add("&3 Title Case",ConvertTitle)
CaseChangeMenu.Add("&4 UPPER CASE",ConvertUpper)
CaseChangeMenu.Add("&5 iNVERT cASE",ConvertInvert)
CaseChangeMenu.Show
}
ConvertLower(*) {
CallClipboard(2)
A_Clipboard := StrLower(A_Clipboard)
CaseConvert()
}
ConvertSentence(*) {
CallClipboard(2)
lowered := StrLower(A_Clipboard)
A_Clipboard := RegExReplace(lowered, "(((^\s*|([.!?]+\s*))[a-z])|\Wi\W)", "$U1") ; Code Credit #1
CaseConvert()
}
ConvertTitle(*) {
CallClipboard(2)
A_Clipboard := StrTitle(A_Clipboard)
CaseConvert()
}
ConvertUpper(*) {
CallClipboard(2)
A_Clipboard := StrUpper(A_Clipboard)
CaseConvert()
}
ConvertInvert(*) {
CallClipboard(2)
inverted := ""
Loop Parse A_Clipboard { ; Code Credit #2
if (StrLower(A_LoopField) == A_LoopField) ; * Code Credit #3
inverted .= StrUpper(A_LoopField) ; *
else ; *
inverted .= StrLower(A_LoopField) ; *
}
A_Clipboard := inverted
CaseConvert()
}
; TestString := "abcdefghijklmnopqrstuvwxyzéâäàåçêëèïîìæôöòûùÿáíóúñ`n"
; . "ABCDEFGHIJKLMNOPQRSTUVWXYZÉÂÄÀÅÇÊËÈÏÎÌÆÔÖÒÛÙŸÁÍÓÚÑ"
; TestInverted := "ABCDEFGHIJKLMNOPQRSTUVWXYZÉÂÄÀÅÇÊËÈÏÎÌÆÔÖÒÛÙŸÁÍÓÚÑ`n"
; . "abcdefghijklmnopqrstuvwxyzéâäàåçêëèïîìæôöòûùÿáíóúñ"
CaseConvert() {
Len := "0"
Len := "+{left " Strlen(A_Clipboard) "}"
Send "^v" ; Pastes new text
Send Len ; and selects it
}
; Code Credit #1 NeedleRegEx pattern modified from the one posted by ManaUser here - //www.autohotkey.com/board/topic/24431-convert-text-uppercase-lowercase-capitalized-or-inverted/?p=158295
; Code Credit #2 idea for loop from kon's post here - https://www.autohotkey.com/boards/viewtopic.php?p=58417#p58417
; Code Credit #3 - 4 lines of code with a comment "; *" were adapted from a (inaccurate) answer generated from a auto-query to DuckDuckGPT by KudoAI via https://greasyfork.org/en/scripts/459849-duckduckgpt
; = Call Clipboard and ClipWait
CallClipboard(secs) {
clipSave := ClipboardAll()
A_Clipboard := ""
Send "^c"
If !ClipWait(secs) {
MyNotification(A_ThisHotkey ":: Clip Failed", "2000", "1650", "985") ; personal preferrence coz tooltip conflict
; ToolTip "Clip Failed" ; Alternatively to MyNotification
; sleep 500
; ToolTip
A_Clipboard := clipSave
clipSave := ""
Exit
}
}
; = Notification GUI
MyNotification(mytext, myduration, xAxis, yAxis) {
MyNotification := Gui()
MyNotification.Opt("+AlwaysOnTop -Caption +ToolWindow") ; +ToolWindow avoids a taskbar button and an alt-tab menu item.
MyNotification.BackColor := "EEEEEE" ; White background
MyNotification.SetFont("s9 w1000", "Arial") ; font size 9, bold
MyNotification.Add("Text", "cBlack Center", mytext) ; black text
MyNotification.Show("x1650 y985 NoActivate") ; NoActivate avoids deactivating the currently active window
WinMove xAxis, yAxis,,, MyNotification
Sleep myduration
MyNotification.Destroy
}
Updates will be posted here On GitHub.
Any suggestions for improving the code are welcome.