Here's a script that I found on
ExpertsExchange (The icons are on that page):
Code: Select all
; Joe Winograd 17-May-2019
#Warn,UseUnsetLocal ; warning on uninitialized variables
#NoEnv ; avoid checking empty variables to see if they are environment variables
#SingleInstance Force ; replace old instance immediately
SetBatchLines,-1 ; run at maximum speed
Gosub,InitializeVars ; initialize all variables
Gosub,ConfigureInitialTray ; configure initial system tray (notification area)
CapsLock:: ; catch CapsLock key
KeyWait,CapsLock ; CapsLock pressed, but wait until user releases it
Gosub,ToggleCapsLock ; CapsLock released, now toggle its state
Return
InitializeVars:
TrayIconON:=A_ScriptDir . "\CapsLockON.ico" ; icon to display in tray when CapsLock is on
TrayIconOFF:=A_ScriptDir . "\CapsLockOFF.ico" ; icon to display in tray when CapsLock is off
Return
ConfigureInitialTray:
Menu,Tray,NoStandard ; do not show standard AutoHotkey tray context menu
Menu,Tray,Add,&Toggle CapsLock,ContextMenu ; first context menu choice is Toggle (T is access key)
Menu,Tray,Add,E&xit,ContextMenu ; second context menu choice Exit (X is access key)
Menu,Tray,Default,&Toggle CapsLock ; Toggle is default
Menu,Tray,Click,1 ; allow a single-click instead of a double-click to toggle CapsLock
Gosub,GetKeyStateIconTip ; get current state of CapsLock and set tray icon and tray tip accordingly
Menu,Tray,Icon,%TrayIcon% ; display On or Off tray icon
Menu,Tray,Tip,%TrayTip% ; display On or Off tray tip
Return
GetKeyStateIconTip:
If (GetKeyState("CapsLock","T")) ; check CapsLock state
{
TrayIcon:=TrayIconON ; CapsLock is On - set tray icon accordingly
TrayTip:="CapsLock ON" ; CapsLock is On - set tray tip accordingly
}
Else
{
TrayIcon:=TrayIconOFF ; CapsLock is Off - set tray icon accordingly
TrayTip:="CapsLock OFF" ; CapsLock is Off - set tray tip accordingly
}
Return
ToggleCapsLock:
If (GetKeyState("CapsLock","T")) ; check CapsLock state
{
SetCapsLockState,Off ; CapsLock is On - turn it Off
TrayIcon:=TrayIconOFF ; Set tray icon to Off
TrayTip:="CapsLock OFF" ; ; Set tray tip to Off
}
Else
{
SetCapsLockState,On ; CapsLock is Off - turn it On
TrayIcon:=TrayIconON ; Set tray icon to On
TrayTip:="CapsLock ON" ; Set tray tip to On
}
Menu,Tray,Icon,%TrayIcon% ; display On or Off tray icon
Menu,Tray,Tip,%TrayTip% ; display On or Off tray tip
Return
ContextMenu:
; check which context menu selected
If (A_ThisMenuItem="&Toggle CapsLock") ; true means Toggle selected
{
Gosub,ToggleCapsLock ; toggle CapsLock state
Return
}
If (A_ThisMenuItem="E&xit") ; true means Exit selected, but make sure it was not accidental
{
MsgBox,4388,Terminate CapsLockOSD?,Are you sure you want to quit? ; 4388 means No is default button, in case of accidental Enter key
IfMsgBox,No
Return ; user does not really want to quit - stay running
}
ExitApp ; user wants to quit - terminate app
I need help, This didn't work:
Code: Select all
; Joe Winograd 17-May-2019
#Warn,UseUnsetLocal ; warning on uninitialized variables
#NoEnv ; avoid checking empty variables to see if they are environment variables
#SingleInstance Force ; replace old instance immediately
SetBatchLines,-1 ; run at maximum speed
CapsLock:: ; catch CapsLock key
KeyWait,CapsLock ; CapsLock pressed, but wait until user releases it
Gosub,ToggleCapsLock ; CapsLock released, now toggle its state
Return
ToggleCapsLock:
If (GetKeyState("CapsLock","T")) ; check CapsLock state
{
SetCapsLockState,Off ; CapsLock is On - turn it Off
ToolTip:="CapsLock is ON"
}
Else
{
SetCapsLockState,On ; CapsLock is Off - turn it On
ToolTip:="CapsLock is ON"
}
ExitApp ; user wants to quit - terminate app