At the risk of getting chewed out for waking up a 5 year old thread: I ran across this script and love it. I use this at work in converting procedural steps into Title Case. The only thing missing was the ability to convert them back to Sentence case when I copy/paste them out of our procedure program for use in emails or other correspondence.
Changed in this version:
- Moved HotKey higher up in code in order to make it work on my laptop (Not sure if this is due to Win7, the AutoHotKey version or what).
- Added ability to change the Toggle timer and TimeOut timer with an ini file for storing options.
- Added Sentence Case option
- 'About' displays current timer settings (haven't worked it over enough to make it round nicely though)
Code:
; Slows down and extends the capslock key.
; Original programming by skrommel with modifications by evl and k.freeman.
; Code for Sentence case borrowed from JDN and ManaUser.
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
CapsLock::
SetTimer,TOOLTIP,1500
SetTimer,TOOLTIP,Off
iniRead, TimeCapsToggle, CAPShift.ini, Settings, TimeCapsToggle, 40
iniRead, TimeOut, CAPShift.ini, Settings, TimeOut, 100
ToggleTimer := TimeCapsToggle/1000
MenuTimer := TimeOut/1000
About =
(LTrim0
Slows down and extends the capslock key.
Hold for %ToggleTimer% sec to toggle capslock on or off.
Hold for %MenuTimer% sec to show a menu that converts selected text to
UPPER CASE, lower case, Title Case, iNVERT cASE, etc
)
counter=0
Progress, ZH16 ZX0 ZY0 B R0-%TimeOut%
Loop, %TimeOut%
{
Sleep,10
counter+=1
Progress, %counter% ;, SubText, MainText, WinTitle, FontName
If (counter = TimeCapsToggle)
Progress, ZH16 ZX0 ZY0 B R0-%TimeOut% CBFF0000
GetKeyState,state,CapsLock,P
If state=U
Break
}
Progress, Off
If counter=%TimeOut%
Gosub,MENU
Else If (counter>TimeCapsToggle)
Gosub, CapsLock_State_Toggle
Return
MENU:
Winget, Active_Window, ID, A
Send,^c
ClipWait,20
Menu,convert,Add
Menu,convert,Delete
Menu, misc ,Add,&About,ABOUT
Menu, misc ,Add,&Quit,QUIT
Menu, misc ,Add,&Toggle Timer,TTIMER
Menu, misc ,Add,&Menu Timer, MTIMER
Menu,convert,Add,CAPShift, :misc
Menu,convert,Add,
Menu,Convert,Add,&CapsLock Toggle,CapsLock_State_Toggle
Menu,convert,Add,
; NOTE: A_ThisMenuItem is used to determine the action to take
Menu,convert,Add,&UPPER CASE,MENU_ACTION
Menu,convert,Add,&lower case,MENU_ACTION
Menu,convert,Add,&Sentence case,MENU_ACTION
Menu,convert,Add,&Title Case,MENU_ACTION
Menu,convert,Add,&iNVERT cASE,MENU_ACTION
Menu,convert,Add,Remove_&under_scores,MENU_ACTION
Menu,convert,Add,Remove.&full.stops,MENU_ACTION
Menu,convert,Default,&CapsLock Toggle
Menu,convert,Show
Return
MENU_ACTION:
AutoTrim,Off
string=%clipboard%
clipboard:=Menu_Action(A_ThisMenuItem, string)
WinActivate, ahk_id %Active_Window%
Send,^v
ToolTip,Selection converted to %A_ThisMenuItem%
SetTimer,TOOLTIP,On
Return
Menu_Action(ThisMenuItem, string)
{
If ThisMenuItem =&UPPER CASE
StringUpper,string,string
Else If ThisMenuItem =&lower case
StringLower,string,string
Else if ThisMenuItem =&Sentence case
{
MsgBox, 4, WARNING, This WILL affect proper nouns. Continue anyway?
ifMsgBox, Yes
StringLower, string, string
string := RegExReplace(string, "(((^|([.!?]\s+))[a-z])| i | i')", "$u1")
}
Else If ThisMenuItem =&Title Case
StringLower,string,string,T
Else If ThisMenuItem =&iNVERT cASE
{
StringCaseSense,On
lower=abcdefghijklmnopqrstuvwxyz
upper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
StringLen,length,string
Loop,%length%
{
StringLeft,char,string,1
StringGetPos,pos,lower,%char%
pos+=1
If pos<>0
StringMid,char,upper,%pos%,1
Else
{
StringGetPos,pos,upper,%char%
pos+=1
If pos<>0
StringMid,char,lower,%pos%,1
}
StringTrimLeft,string,string,1
string.=char
}
StringCaseSense,Off
}
Else If ThisMenuItem =Remove_&under_scores
StringReplace, string, string,_,%A_Space%, All
Else If ThisMenuItem =Remove.&full.stops
StringReplace, string, string,.,%A_Space%, All
Return string
}
EMPTY:
Return
TOOLTIP:
ToolTip,
SetTimer,TOOLTIP,Off
Return
CapsLock_State_Toggle:
If GetKeyState("CapsLock","T")
state=Off
Else
state=On
CapsLock_State_Toggle(state)
Return
CapsLock_State_Toggle(State)
{
SetCapsLockState,%State%
ToolTip,CapsLock %State%
SetTimer,TOOLTIP,On
}
TTIMER:
inputBox, TTIME, CAPShift, Enter the amount of time you want to press the key to toggle CapsLock on/off (1000 = 1 second),, 320, 140
if TTIME !=
{
iniWrite, %TTIME%, CAPShift.ini, Settings, TimeCapsToggle
sleep 100
reload
}
return
MTIMER:
inputBox, MTIME, CAPShift, Enter the amount of time you want to press the key to bring up the CAPShift Menu (1000 = 1 second),, 320, 140
if MTIME !=
{
iniWrite, %MTIME%, CAPShift.ini, Settings, TimeOut
sleep 100
reload
}
return
ABOUT:
MsgBox,0,CAPShift,%About%
Return
QUIT:
ExitApp
Hope this is useful to somebody.
I also modified this (a lot) to use as a custom print menu tied to the prntscrn key. That script currently isn't usable on any other machine though, its too dependent on my personal printer settings.
-k.freeman