Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

CAPshift: Slow down and extend the caps lock key


  • Please log in to reply
24 replies to this topic
skrommel
  • Members
  • 193 posts
  • Last active: Jun 07 2010 08:30 AM
  • Joined: 30 Jul 2004
:D The ultimate Caps Lock extender!

CAPshift slows down and extends the caps lock key.

Hold down caps lock for 0.4 sec to toggle caps lock on or off.
Hold for 0.9 sec to show a menu that converts selected text to UPPER CASE, lower case, Title Case or iNVERT cASE.

Some of the ideas came from Ampa on another forum.

Skrommel


;CAPshift.ahk
;Slows down and extends the cap locks key.
;
;Hold for 0.4 sec to toggle caps lock on or off.
;Hold for 0.9 sec to show a menu that converts selected text to 
; UPPER CASE, lower case, Title Case or iNVERT cASE.
;Skrommel @2005

SetTimer,TOOLTIP,1500
SetTimer,TOOLTIP,Off

CapsLock::
counter=0
Loop,90
{
  Sleep,10
  counter+=1
  If counter=40
    SoundPlay,%SYSTEMROOT%\Media\ding.wav
  GetKeyState,state,CapsLock,P
  If state=U
    Break
}
If counter=90
  Gosub,MENU
Else
If counter>40
{
  GetKeyState,state,CapsLock,T
  If state=D
    Gosub,OFF
  Else
    Gosub,ON
}
Return

MENU:
Menu,convert,Add
Menu,convert,Delete
Menu,convert,Add,CAPshift,EMPTY
Menu,convert,Add,
Menu,Convert,Add,CapsLock &On,On
Menu,Convert,Add,&CapsLock Off,Off
Menu,convert,Add,
Menu,convert,Add,&UPPER CASE,UPPER
Menu,convert,Add,&lower case,LOWER
Menu,convert,Add,&Title Case,TITLE
Menu,convert,Add,&iNVERT cASE,INVERT
Menu,convert,Add,
Menu,convert,Add,&About,ABOUT
Menu,convert,Add,&Quit,QUIT
Menu,convert,Default,CapShift
Menu,convert,Show
Return

EMPTY:
Return

TOOLTIP:
ToolTip,
SetTimer,TOOLTIP,Off
Return

ON:
SetCapsLockState,On
ToolTip,CapsLock On
SetTimer,TOOLTIP,On
Return

OFF:
SetCapsLockState,Off
ToolTip,CapsLock Off
SetTimer,TOOLTIP,On
Return

CUT:
Send,^x
ClipWait,1
string=%clipboard%
Return

PASTE:
clipboard=%string%
Send,^v
Return

UPPER:
Gosub,CUT
StringUpper,string,string
Gosub,PASTE
ToolTip,Selection converted to UPPER CASE
SetTimer,TOOLTIP,On
Return

LOWER:
Gosub,CUT
StringLower,string,string
Gosub,PASTE
ToolTip,Selection converted to lower case
SetTimer,TOOLTIP,On
Return

TITLE:
Gosub,CUT
StringLower,string,string,T
Gosub,PASTE
ToolTip,Selection converted to Title Case
SetTimer,TOOLTIP,On
Return

INVERT:
AutoTrim,Off 
StringCaseSense,On
Gosub,CUT
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=%string%%char%
}
ToolTip,Selection converted to iNVERTED cASE
SetTimer,TOOLTIP,On
Gosub,PASTE
Return

ABOUT:
MsgBox,0,CAPshift,CAPshift slows down and extends the caps lock key.`n`nHold down caps lock for 0.4 sec to toggle caps lock on or off.`nHold for 0.9 sec to show a menu that converts selected text to UPPER CASE, lower case, Title Case or iNVERT cASE.`n`nSkrommel @2005
Return

QUIT:
ExitApp


Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
"Overloading" the Caps Lock key in this way seems to be a great innovation. Thanks for posting it.

jack
  • Members
  • 75 posts
  • Last active: Oct 29 2010 08:33 PM
  • Joined: 04 Sep 2004
really nice!

i abandoned capslock ages ago -- it's far more useful to have it run my file manager -- but with a tiny edit i can have the file manager and your functionality too.

great stuff.

thanks

jack
tomorrow's almost over, today went by so fast...

bor
  • Guests
  • Last active:
  • Joined: --
I mad a little extension to this script.
It changes someTextHere to SOME_TEXT_HERE



DASHES:
AutoTrim,Off
StringCaseSense,On
Gosub,COPY
lower=abcdefghijklmnopqrstuvwxyzaoa
upper=ABCDEFGHIJKLMNOPQRSTUVWXYZAOA
StringLen,length,string

iter:=0
Loop,%length%
{
  StringLeft,char,string,1
  StringGetPos,pos,lower,%char%
  pos+=1
  If pos<>0
    StringMid,char,upper,%pos%,1
  Else ;pos==0
  {
    StringGetPos,pos,upper,%char%
    pos+=1
    If pos<>0
    {
      StringMid,char,upper,%pos%,1
      If iter<>0
        char=_%char%
    }
  }
  StringTrimLeft,string,string,1
  string=%string%%char%
  iter+=1
}
ToolTip,Selection converted to KRECHY
SetTimer,TOOLTIP,On
Gosub,PASTE
Return


evl
  • Members
  • 1237 posts
  • Last active: Oct 20 2010 11:41 AM
  • Joined: 24 Aug 2005
Nice ideas. I made a few changes to the script and added a progress bar to display how long the button has been pressed (and it changes colour to show the phase you can turn the Capslock on).

#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.


About =
(LTrim0
Slows down and extends the capslock key.

Hold for 0.2 sec to toggle capslock on or off.
Hold for 0.5 sec to show a menu that converts selected text to 
UPPER CASE, lower case, Title Case, iNVERT cASE, etc
)

SetTimer,TOOLTIP,1500
SetTimer,TOOLTIP,Off
TimeCapsToggle =20
TimeOut =50
CapsLock::
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,1
Menu,convert,Add
Menu,convert,Delete
Menu, misc  ,Add,&About,ABOUT
Menu, misc  ,Add,&Quit,QUIT
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,&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 =&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
}


ABOUT:
MsgBox,0,CAPshift,%About%
Return

QUIT:
ExitApp


jfty.009260
  • Members
  • 8 posts
  • Last active: Jul 31 2008 02:49 PM
  • Joined: 18 Mar 2008
Wow, evl, that is a very nice mod of CAPshift!

SoggyDog
  • Members
  • 803 posts
  • Last active: Mar 04 2013 06:27 AM
  • Joined: 02 May 2006
I've meant to post here a million times (really, I kept track) and finally getting around to it.
I am forever hitting the capslock and this is my only saving grace.

Thanks - I love it.

vahju
  • Members
  • 337 posts
  • Last active: Sep 21 2014 03:52 AM
  • Joined: 17 Feb 2008
This is a great script and I love evl's version.

When I go to include this script with mine (using include) depending on where I put the include it either doesn't work or works and prevents my other code from working.

When using include with evl's version is there anything I should remove?

steve264
  • Members
  • 1 posts
  • Last active: Dec 01 2010 02:49 PM
  • Joined: 16 Jun 2008
Hi,

Great script, but it causes me a problem because another application I use has a double-press of the Caps Lock key as a hard-coded keystroke.

I would like to modify the CAPshift.ahk script to recognise that the Caps Lock has been pressed twice rapidly, and if so, just exit without doing anything.

I don't have the knowledge or skill to do this mod myself, can anyone please help out?

Many thanks,
Steve

:)

Mike the K
  • Members
  • 2 posts
  • Last active: Oct 31 2009 08:51 PM
  • Joined: 17 Dec 2007
Hi.

Can someone help me add CAPshift menu options to surround the current selection with parens and maybe brackets? I tried returning the entire string with SubStr(string,1), but I couldn't figure out how to concatenate the extra characters...

Thanks in advance,

-Mike.

Mike the K
  • Members
  • 2 posts
  • Last active: Oct 31 2009 08:51 PM
  • Joined: 17 Dec 2007

Can someone help me add CAPshift menu options to surround the current selection with parens and maybe brackets?

Never mind: string=(%string%).
Next time I'll try the painfully obvious before asking... :oops:

-Mike.

k.freeman
  • Members
  • 1 posts
  • Last active: Aug 31 2010 04:18 AM
  • Joined: 31 Aug 2010
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)


; 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

nascent
  • Members
  • 3 posts
  • Last active: Mar 02 2017 02:52 PM
  • Joined: 10 Nov 2011

UPDATE:  As this forum is now archived I have created CAPshift 2.0 and posted it here

 

Note: All versions of this script fail when caps lock is pressed along with another modifier key. My version now fixes this:

I've been using some shareware by the name of sMaRTcaPs for a while, and while it worked, it wasn't free, and was very buggy (randomly will toggle caps, randomly decides it wants indefinite caps lock ON, etc).

Finally discovered this script, which is awesome!

I didn't want the visual mods, the sound effect didn't work on Win7 for me (don't think I have the wav), there is a bug in the other scripts where additional modifier keys break the script and I wanted a longer delay for the menu.

So I too did a version of the script, which I compiled with an icon I found:
Sta2R.png

So here's my version:
(exe download mirrors for those that don't want to compile it themselves)

http://depositfiles....files/3xdgqm3sn http://uppit.com/CAPshift.exe http://www.fileswap....Pshift.exe.html http://filerio.in/vcclime5qtxk http://uptobox.com/mow1f1tc6gxm http://www.putlocker...0402AC0AF95D216 http://bitshare.com/...Pshift.exe.html
 

;CAPshift.ahk

;Slows down and extends the cap locks key.

;

;Hold for 0.4 sec to toggle caps lock on or off.

;Hold for 1.2 sec to show a menu that converts selected text to

; UPPER CASE, lower case, Title Case or iNVERT cASE.

;Original Author=Skrommel @2005

;Modified by nascent





SetTimer,TOOLTIP,1500

SetTimer,TOOLTIP,Off



*CapsLock::

counter=0

Loop,200

{

Sleep,10

counter+=1

If counter=40

;SoundPlay,%SYSTEMROOT%\Media\ding.wav

SoundBeep

GetKeyState,state,CapsLock,P

If state=U

Break

}

If counter=200

Gosub,MENU

Else

If counter>40

{

GetKeyState,state,CapsLock,T

If state=D

Gosub,OFF

Else

Gosub,ON

}

Return



MENU:

Menu,convert,Add

Menu,convert,Delete

Menu,convert,Add,CAPshift,EMPTY

Menu,convert,Add,

Menu,Convert,Add,CapsLock &On,On

Menu,Convert,Add,&CapsLock Off,Off

Menu,convert,Add,

Menu,convert,Add,&UPPER CASE,UPPER

Menu,convert,Add,&lower case,LOWER

Menu,convert,Add,&Title Case,TITLE

Menu,convert,Add,&iNVERT cASE,INVERT

Menu,convert,Add,

Menu,convert,Add,&About,ABOUT

Menu,convert,Add,&Quit,QUIT

Menu,convert,Default,CapShift

Menu,convert,Show

Return



EMPTY:

Return



TOOLTIP:

ToolTip,

SetTimer,TOOLTIP,Off

Return



ON:

SetCapsLockState,On

ToolTip,CapsLock On

SetTimer,TOOLTIP,On

Return



OFF:

SetCapsLockState,Off

ToolTip,CapsLock Off

SetTimer,TOOLTIP,On

Return



CUT:

Send,^x

ClipWait,1

string=%clipboard%

Return



PASTE:

clipboard=%string%

Send,^v

Return



UPPER:

Gosub,CUT

StringUpper,string,string

Gosub,PASTE

ToolTip,Selection converted to UPPER CASE

SetTimer,TOOLTIP,On

Return



LOWER:

Gosub,CUT

StringLower,string,string

Gosub,PASTE

ToolTip,Selection converted to lower case

SetTimer,TOOLTIP,On

Return



TITLE:

Gosub,CUT

StringLower,string,string,T

Gosub,PASTE

ToolTip,Selection converted to Title Case

SetTimer,TOOLTIP,On

Return



INVERT:

AutoTrim,Off

StringCaseSense,On

Gosub,CUT

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=%string%%char%

}

ToolTip,Selection converted to iNVERTED cASE

SetTimer,TOOLTIP,On

Gosub,PASTE

Return



ABOUT:

MsgBox,0,CAPshift,CAPshift slows down and extends the caps lock key.`n`nHold down caps lock for 0.4



sec to toggle caps lock on or off.`nHold for 1.2 sec to show a menu that converts selected text to



UPPER CASE, lower case, Title Case or iNVERT cASE.`n`nSkrommel @2005 (Modified by nascent)

Return



QUIT:

ExitApp


Carrozza
  • Members
  • 214 posts
  • Last active: Mar 02 2016 09:51 AM
  • Joined: 05 Jul 2009
Interesting stuff here.

Foo
  • Members
  • 37 posts
  • Last active: Nov 23 2011 02:22 AM
  • Joined: 09 Feb 2006
Thank you all. This is soooo useful! KUDOS!