Guest User

Capslock override(toCaps, toLower, Capitalized)

a guest
Jun 29th, 2015
326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. CapsLock::                          ; the invoking key
  2.     SetCapsLockState, Off           ; turn it off right away because no one wants that
  3.     oldClipboard := Clipboard       ; we're mucking with the clipboard, so save for later
  4.     Send, {ctrl down}c{ctrl up}     ; copy whatever we have selected
  5.     if (StrLen(Clipboard) = 0) {    ; empty clipboard, get out fast
  6.         Clipboard := oldClipboard   ; reset clipboard
  7.         exit
  8.     }
  9.     StringUpper, uppered, Clipboard     ; used a couple times so made a variable
  10.     StringLower, lowered, Clipboard     ; ditto
  11.     if (lowered == Clipboard)           ; if we're the lower case version of the selection
  12.         Clipboard := uppered            ; upper case it
  13.     else if (uppered == Clipboard)      ; if we're the upper case version for the selection
  14.         Clipboard := RegExReplace(lowered, "((?:^|[.!?]\s+)[a-z])", "$u1")      ; sentence case it http://www.autohotkey.com/board/topic/24431-convert-text-uppercase-lowercase-capitalized-or-inverted/
  15.     else                                ; otherwise
  16.         Clipboard := lowered            ; lower case it
  17.     Send, {ctrl down}v{ctrl up}         ; paste what we just altered
  18.     selectionLength := StrLen(Clipboard); get the string length
  19.     Send, {shift down}{Left %selectionLength%}{shift up}; select the n characters to the left of the paste
  20.     Clipboard := oldClipboard                           ; put the old clipboard back
Advertisement
Add Comment
Please, Sign In to add comment