Caps on / off based on process / window

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
montyLalor
Posts: 8
Joined: 10 Dec 2017, 06:28

Caps on / off based on process / window

11 Dec 2017, 01:37

Hi,

I'm Luke. I'm new to this AHK world. Not looking for recognition, but I thought I'd share my first functioning script.

I'm a draftsperson and CAPS ON is very useful while drawing (mostly), but painful while composing emails etc.

I have successfully reduced a tangible level of frustration from the daily grind :dance: with this script:

Code: Select all

#Persistent

SetTimer, WinActive, 500
return

WinActive:
WinGet, ActiveProcess, ProcessName, A
;MsgBox, 131136, DebugInfo1, %ActiveProcess%,
If ActiveProcess Contains acad,excel,notepad
{
	GetKeyState, CapsOnOff, CapsLock, T
	;MsgBox, 131136, DebugInfo2, %CapsOnOff%,
	IfEqual, CapsOnOff, On
	{
		return
	}
	else
		{
		SetCapsLockState, On
		return
		}
}
	WinGet, ActiveProcess, ProcessName, A
	;MsgBox, 131136, DebugInfo3, %ActiveProcess%,
	If ActiveProcess Contains Inventor
	{
		WinGetTitle, ActiveTitle, A
		;MsgBox, 131136, DebugInfo4, %ActiveTitle%,
		If ActiveTitle = Format%A_Space%Text
		{
			GetKeyState, CapsOnOff, CapsLock, T
			;MsgBox, 131136, DebugInfo5, %CapsOnOff%,
			IfEqual, CapsOnOff, On
			{
				return
			}
			else
				{
				SetCapsLockState, On
				return
				}
		}	
			WinGetTitle, ActiveTitle, A
			;MsgBox, 131136, DebugInfo6, %ActiveTitle%,
			If ActiveTitle = Edit%A_Space%Dimension
			{
				GetKeyState, CapsOnOff, CapsLock, T
				;MsgBox, 131136, DebugInfo7, %CapsOnOff%,
				IfEqual, CapsOnOff, On
				{
					return
				}
				else
					{
					SetCapsLockState, On
					return
					}
			}
	}
	GetKeyState, CapsOnOff, CapsLock, T
	;MsgBox, 131136, DebugInfo8, %CapsOnOff%,
	IfEqual, CapsOnOff, Off
	{
		return
	}
	else
		{
		SetCapsLockState, Off
		return
		}
return
My AHK knowledge currently manoeuvres with the eloquence of a fiery wall of disintegrating fuselage...
User avatar
boiler
Posts: 16963
Joined: 21 Dec 2014, 02:44

Re: Caps on / off based on process / window

12 Dec 2017, 16:30

Hi, Luke. Welcome to the forum. It's good to see people post real-world examples of how they use AHK to make their jobs easier and/or make them more efficient.
User avatar
montyLalor
Posts: 8
Joined: 10 Dec 2017, 06:28

Re: Caps on / off based on process / window

19 Dec 2017, 07:39

Here's an update to the previous posted script. It now displays a 'splash' when the CapState changes. PM me if you'd like the images I've created, although creating your own is rewarding, imho. Just be sure to make the background transparent...

Merry Christmas!

Code: Select all

#Persistent, #NoEnv
SetWorkingDir %A_ScriptDir%

Gui, 1: add, picture, , caps-off.png
Gui, 2: add, picture, , CAPS-ON.png

SetTimer, WinActive, 500
return

WinActive:
WinGet, ActiveProcess, ProcessName, A
If ActiveProcess Contains acad,excel,notepad
{
	GetKeyState, CapsOnOff, CapsLock, T
	IfEqual, CapsOnOff, D
	{
		return
	}
	else
		{
		SetCapsLockState, On
		gosub, CapsSplash
		return
		}
}
	WinGet, ActiveProcess, ProcessName, A
	If ActiveProcess Contains Inventor
	{
		WinGetTitle, ActiveTitle, A
		If ActiveTitle = Format%A_Space%Text
		{
			GetKeyState, CapsOnOff, CapsLock, T
			IfEqual, CapsOnOff, D
			{
				return
			}
			else
				{
				SetCapsLockState, On
				gosub, CapsSplash
				return
				}
		}	
			WinGetTitle, ActiveTitle, A
			If ActiveTitle = Edit%A_Space%Dimension
			{
				GetKeyState, CapsOnOff, CapsLock, T
				IfEqual, CapsOnOff, D
				{
					return
				}
				else
					{
					SetCapsLockState, On
					gosub, CapsSplash
					return
					}
			}
	}
	GetKeyState, CapsOnOff, CapsLock, T
	IfEqual, CapsOnOff, U
	{
		return
	}
	else
		{
		SetCapsLockState, Off
		gosub, CapsSplash
		return
		}
return

CapsSplash:
GetKeyState, CapsOnOff, CapsLock, T
IfEqual, CapsOnOff, U
	{
		Gui 1: Color, 263158
		Winset, Transcolor, 263158
		Gui 1: -Caption +Alwaysontop
		Gui 1: Show
		Sleep, 475
		Gui 1: Hide
		return
	}
IfEqual, CapsOnOff, D
	{
		Gui 2: Color, 263158
		Winset, Transcolor, 263158
		Gui 2: -Caption +Alwaysontop
		Gui 2: Show
		Sleep, 475
		Gui 2: Hide
		return
	}
return
My AHK knowledge currently manoeuvres with the eloquence of a fiery wall of disintegrating fuselage...

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 129 guests