Code: Select all
^NumpadAdd:: { ; Hotkey to make selected text uppercase
OldClipboardBackup := ClipboardAll() ; Save the entire clipboard to a variable (OldClipboardBackup).
A_Clipboard := "" ; Empties the Clipboard.
Send("^c") ; Sends Control + C (Copy) to copy text. (This is to check if text is currently selected)
Errorlevel := !ClipWait(0.1) ; Waits 0.1 second and then checks the status of the clipboard
If(A_Clipboard = ""){ ; If Clipboard is empty => no text was previously selected
Send("^a") ; Will send control + a to select everything in the active window
Sleep(10) ; Waits for 10ms to make sure text has been selected
Send("^c") ; Copies selected text.
Errorlevel := !ClipWait(0.1) ; Will wait 0.1 seconds and then check the status of the clipboard. It should now contain text since text was previously copied and will proceed to the next if statement.
}
If(A_Clipboard != ""){ ; If Clipboard is not empty, proceed
A_Clipboard := StrUpper(A_Clipboard) ; Turns all letters into uppercase form in the clipboard
Send("^v") ; Will send the text in clipboard with all uppercase (Replaces old case by uppercase)
Sleep(1000) ; Added the sleep incase the processing would outrun the script without first sending the manipulated data string
}
A_Clipboard := OldClipboardBackup ; Restore the original clipboard. Note the use of Clipboard (not ClipboardAll).
OldClipboardBackup := "" ; Free the memory in case the clipboard was very large. (Our variable "OldClipboardBackup" becomes empty)
}