Jump to content

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

Auto CapsLock


  • Please log in to reply
18 replies to this topic
KWest
  • Members
  • 1 posts
  • Last active: Oct 31 2009 07:38 PM
  • Joined: 20 Apr 2009
I'm looking for a way to turn On/Off caps lock depending if a program is active or not. All my text is UPPERCASE in autocad, so I would like to have capslock turn on as soon as it's active, and when any other window is activated it would turn off.

; AutoCad Not Active Reset Capslock
#IfWinNotActive AutoCAD
	SetTitleMatchMode 2
	SetCapsLockState,Off ; Doesn't work
        Send {SetCapsLockState,Off} ; Doesn't work
        Send {CapsLock} ; Doesn't work
; Autocad Setup
#IfWinActive AutoCAD
	SetTitleMatchMode 2
	MButton::MButton	
	XButton1::^+c
	^LButton::^v

Thanks in advance

  • Guests
  • Last active:
  • Joined: --
SetCapsLockState,Off
runs by itself....no need to put "send" in front
also, u can try:
#IfWinActive AutoCAD
CapsLock::return


MasterFocus
  • Moderators
  • 4323 posts
  • Last active: Jan 28 2016 01:38 AM
  • Joined: 08 Apr 2009
SetTitleMatchMode, 2

SetTimer, CheckBecameActive, 100

Return



CheckBecameActive:

  IfNotWinActive, AutoCAD

    Return

  SetTimer, CheckBecameActive, Off

  SetTimer, CheckBecameInactive, 100

  SetCapsLockState, On

Return



CheckBecameInactive:

  IfWinActive, AutoCAD

    Return

  SetTimer, CheckBecameInactive, Off

  SetTimer, CheckBecameActive, 100

  SetCapsLockState, OFF

Return



#IfWinActive AutoCAD

   XButton1::^+c

   ^LButton:: Send, ^v

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Antonio França -- git.io -- github.com -- ahk4.net -- sites.google.com -- ahkscript.org

Member of the AHK community since 08/Apr/2009. Moderator since mid-2012.


Crash&Burn
  • Members
  • 228 posts
  • Last active: Jul 16 2014 10:10 PM
  • Joined: 02 Aug 2009
I believe you would need to set a Timer to check what the active window was every 100/200 ms or so.

The other option, if you always switch applications with ALT+TAB would be to trigger on that.
SetCapsLockState, Off

SetTimer, ToggleCapsLock, 200

ToggleCapsLock: 
{
	if( WinActive( "ahk_class AutoCAD" ) && !GetKeyState("CapsLock", "T") )
	{
		SetCapsLockState, On
		gCapsLock := 1
	}
	else
	if( !WinActive( "ahk_class AutoCAD" ) && gCapsLock )
	{
		SetCapsLockState, Off
		gCapsLock := 0
	}
return
}
This will automatically turn CapsLock off when you switch to another program, but will also allow you to manually turn CapsLock ON if so desired.

GuestToo!
  • Guests
  • Last active:
  • Joined: --
I've tried every solution posted here to no avail... I, too, am looking for this exact function. I switch in and out of a program that will only recognize uppercase characters, and I constantly forget to switch.

Can someone provide the complete code (other than the window name, I'll get that at work)?

Thanks!

Crash&Burn
  • Members
  • 228 posts
  • Last active: Jul 16 2014 10:10 PM
  • Joined: 02 Aug 2009
Mine works. It's been tested with something I know the ahk_class for (i.e. an Editor). I have no idea what AutoCAD's ahk_class is: that would need to be changed if it isn't "AutoCAD".

MasterFocus
  • Moderators
  • 4323 posts
  • Last active: Jan 28 2016 01:38 AM
  • Joined: 08 Apr 2009
@GuestToo!: Copy the code I provided, remove the #IfWinActive part
and change from AutoCAD to the name of the desired window.

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Antonio França -- git.io -- github.com -- ahk4.net -- sites.google.com -- ahkscript.org

Member of the AHK community since 08/Apr/2009. Moderator since mid-2012.


Eedis
  • Members
  • 1775 posts
  • Last active: Aug 14 2015 06:33 PM
  • Joined: 12 Jun 2009
Shouldn't there be a space in this code?

SetCapsLockState,Off ; Doesn't work 
        Send {SetCapsLockState,Off} ; Doesn't work 
        Send {CapsLock} ; Doesn't work
...
SetCapsLockState, Off ; Doesn't work 
        Send {SetCapsLockState, Off} ; Doesn't work 
        Send {CapsLock} ; Doesn't work

AutoHotkey state, the forum, Poly, and Drainx1. The short story.
I love my wife, my life, my atomic-match; for giving me the greatest gift a man could ask for, such a perfect and beautiful little girl.
9rjbjc.png

Crash&Burn
  • Members
  • 228 posts
  • Last active: Jul 16 2014 10:10 PM
  • Joined: 02 Aug 2009
The Send's don't work, but these do:
SetCapsLockState, On
SetCapsLockState, Off

I've used similiar for my own purposes:
CAPSLOCK::Send, *
+CAPSLOCK::Send, `%
!CAPSLOCK::SetCapslockState, % ( Toggle( capsLockState ) ? "On" : "Off" )
Capslock, sends: *
Shift + Capslock, sends %
and ALT + Capslock, does a normal Capslock.

Requires, Toggle.ahk
Toggle(byRef onOff, displayVar="")
{
	onOff := ( onOff == 0 ) ? 1 : 0
	if( displayVar <> "" )
		MsgBox, ,, %displayVar%: %onOff%, 1
return onOff
}


Rolf Espen
  • Guests
  • Last active:
  • Joined: --

I'm looking for a way to turn On/Off caps lock depending if a program is active or not. All my text is UPPERCASE in autocad, so I would like to have capslock turn on as soon as it's active, and when any other window is activated it would turn off.

; AutoCad Not Active Reset Capslock
#IfWinNotActive AutoCAD
	SetTitleMatchMode 2
	SetCapsLockState,Off ; Doesn't work
        Send {SetCapsLockState,Off} ; Doesn't work
        Send {CapsLock} ; Doesn't work
; Autocad Setup
#IfWinActive AutoCAD
	SetTitleMatchMode 2
	MButton::MButton	
	XButton1::^+c
	^LButton::^v

Thanks in advance



Here is some code I use:

AutoCapsAcad()

#h::
{
Gui, Add, Text,, Caps Lock disabled
Gui, Add, Text,, Ctrl+Caps Lock = Caps On/Off
Gui, Add, Text,, Win+L turn off Caps before locking workstation
Gui, Show
}
Return

; Disable Caps Lock
Capslock::Return
; Ctrl+Caps Lock = Caps Lock
^Capslock::Capslock
;Win+L turn off Caps Lock before locking workstation
#l::
{
SetCapsLockState, off
DllCall("LockWorkStation")
}
Return


#Persistent


AutoCapsAcad()
{
Loop
{
WinGet,WID1,ID,A
isActive1 := isAcadRelated(WID1)

If isActive2 && !isActive1
SetCapsLockState, off
Else If !isActive2 && isActive1
SetCapsLockState, on

Sleep, 200
WinGet,WID2,ID,A
isActive2 := isAcadRelated(WID2)

If isActive1 && !isActive2
SetCapsLockState, off
Else If !isActive1 && isActive2
SetCapsLockState, on
}
}

isAcadRelated(WinID)
{
RetVal = 0
WinGet ProcessName,ProcessName, ahk_id %WinID%
If (ProcessName = "acad.exe")
{
RetVal = 1
}
Return %RetVal%
}

grhmstwrt
  • Guests
  • Last active:
  • Joined: --
Crash&Burn 's script does work, with the provision that there has to be at least one hotkey defined in the same file so it doesn't exit immediately.

Crash&Burn
  • Members
  • 228 posts
  • Last active: Jul 16 2014 10:10 PM
  • Joined: 02 Aug 2009
AH, Well yes it is just 3 lines of my main Hotkey script (1920 lines)... that's
forced to be persistent and single instance only :-)

Interesting that a capslock hotkey doesn't make a script be persistent though. According to the DOCS any hotkey should make a script be persistent.

I do put these lines into almost every single script I have:
#SingleInstance, Force 
	#Persistent
	#NoEnv
SetBatchLInes, -1
Unless a script just does a task and ends, then I wouldn't use "#Persistent"

  • Guests
  • Last active:
  • Joined: --

Here is some code I use:

AutoCapsAcad()

#h::
{
Gui, Add, Text,, Caps Lock disabled
Gui, Add, Text,, Ctrl+Caps Lock = Caps On/Off
Gui, Add, Text,, Win+L turn off Caps before locking workstation
Gui, Show
}
Return

; Disable Caps Lock
Capslock::Return
; Ctrl+Caps Lock = Caps Lock
^Capslock::Capslock
;Win+L turn off Caps Lock before locking workstation
#l::
{
SetCapsLockState, off
DllCall("LockWorkStation")
}
Return


#Persistent


AutoCapsAcad()
{
Loop
{
WinGet,WID1,ID,A
isActive1 := isAcadRelated(WID1)

If isActive2 && !isActive1
SetCapsLockState, off
Else If !isActive2 && isActive1
SetCapsLockState, on

Sleep, 200
WinGet,WID2,ID,A
isActive2 := isAcadRelated(WID2)

If isActive1 && !isActive2
SetCapsLockState, off
Else If !isActive1 && isActive2
SetCapsLockState, on
}
}

isAcadRelated(WinID)
{
RetVal = 0
WinGet ProcessName,ProcessName, ahk_id %WinID%
If (ProcessName = "acad.exe")
{
RetVal = 1
}
Return %RetVal%
}



Thanks a ton this works great. Is it possible to modify it to work in multiple programs?

for example something like

WinGet ProcessName,ProcessName, ahk_id %WinID%
If (ProcessName = "acad.exe" or "msaccess.exe")


I just started using autohotkey and am still reading tutorials.

Crash&Burn
  • Members
  • 228 posts
  • Last active: Jul 16 2014 10:10 PM
  • Joined: 02 Aug 2009

Thanks a ton this works great. Is it possible to modify it to work in multiple programs?

for example something like

WinGet ProcessName,ProcessName, ahk_id %WinID%
If (ProcessName = "acad.exe" or "msaccess.exe")


I just started using autohotkey and am still reading tutorials.

Yes,
if( ProcessName == "acad.exe" or ProcessName == "msaccess.exe" )

The double equal's "==" isn't required, but I find it easier to distinguish between a comparison, and assignment: "=" or ":="
As opposed to determining context (every time) when you look at the code to figure out if "=" is an assignment or comparison.

  • Guests
  • Last active:
  • Joined: --

Thanks a ton this works great. Is it possible to modify it to work in multiple programs?

for example something like

WinGet ProcessName,ProcessName, ahk_id %WinID%
If (ProcessName = "acad.exe" or "msaccess.exe")


I just started using autohotkey and am still reading tutorials.

Yes,
if( ProcessName == "acad.exe" or ProcessName == "msaccess.exe" )

The double equal's "==" isn't required, but I find it easier to distinguish between a comparison, and assignment: "=" or ":="
As opposed to determining context (every time) when you look at the code to figure out if "=" is an assignment or comparison.


Thanks I have this working perpectly now. Autocaps in cad access and excel.