Code: Select all
#Warn,UseUnsetLocal
#NoEnv
#SingleInstance Force
SetBatchLines,-1
Gosub,InitializeVars
Gosub,ConfigureInitialTray
CapsLock::
KeyWait,CapsLock
Gosub,ToggleCapsLock
Return
InitializeVars:
TrayIconON:=A_ScriptDir . "\CapsLockON.ico"
TrayIconOFF:=A_ScriptDir . "\CapsLockOFF.ico"
StartupLink:=A_Startup . "\CapsLockOSD.lnk"
StartupLink:=A_StartupCommon . "\CapsLockOSD.lnk"
CapsLockIcon:=A_ScriptDir . "\CapsLockOSD.ico"
FileInstall,CapsLockON.ico,%TrayIconON%
FileInstall,CapsLockOFF.ico,%TrayIconOFF%
FileInstall,CapsLockOSD.ico,%CapsLockIcon%
Return
ConfigureInitialTray:
Menu,Tray,NoStandard
Menu,Tray,Add,&Toggle CapsLock,ContextMenu
Menu,Tray,Add,&Start with Windows,ContextMenu
Menu,Tray,Add,E&xit,ContextMenu
Menu,Tray,Default,&Toggle CapsLock
Menu,Tray,Click,1
Gosub,GetKeyStateIconTip
Menu,Tray,Icon,%TrayIcon%
Menu,Tray,Tip,%TrayTip%
If (FileExist(StartupLink))
Menu,Tray,Check,&Start with Windows
Else
Menu,Tray,Uncheck,&Start with Windows
Return
GetKeyStateIconTip:
If (GetKeyState("CapsLock","T"))
{
TrayIcon:=TrayIconON
TrayTip:="CapsLock ON"
}
Else
{
TrayIcon:=TrayIconOFF
TrayTip:="CapsLock OFF"
}
Return
ToggleCapsLock:
If (GetKeyState("CapsLock","T"))
{
SetCapsLockState,Off
TrayIcon:=TrayIconOFF
TrayTip:="CapsLock OFF"
}
Else
{
SetCapsLockState,On
TrayIcon:=TrayIconON
TrayTip:="CapsLock ON"
}
Menu,Tray,Icon,%TrayIcon%
Menu,Tray,Tip,%TrayTip%
Return
ContextMenu:
If (A_ThisMenuItem="&Toggle CapsLock")
{
Gosub,ToggleCapsLock
Return
}
If (A_ThisMenuItem="&Start with Windows")
{
If (FileExist(StartupLink))
{
Menu,Tray,Uncheck,&Start with Windows
FileDelete,%StartupLink%
Return
}
Else
{
Menu,Tray,Check,&Start with Windows
FileCreateShortcut,%A_ScriptFullPath%,%StartupLink%,,,CapsLockOSD,%CapsLockIcon%
If (ErrorLevel!=0)
{
MsgBox,4112,Fatal Error,Error code=%ErrorLevel% trying to create shortcut to:`n%A_ScriptName%`nThis should never happen.
ExitApp
}
Return
}
}
If (A_ThisMenuItem="E&xit")
{
MsgBox,4388,Terminate CapsLockOSD?,Are you sure you want to quit?
IfMsgBox,No
Return
}
ExitApp