So I'm having an issue with my script, which was working fine for a period of time and just recently decided to quit working. I piecemealed together the code below so that it would turn off my numlock when I locked my PC and turn it back on when I unlocked the PC. One other thing if we can get this figured out, I would like to add a function to turn off the numlock when the PC goes idle and turns off my monitors. When the PC goes idle it will lock itself, but leaves the numlock on. So I assume that I would have to detect a different change/action for when the PC goes into idle which would trigger turning off the numlock.
Any ideas?
Code: Select all
DetectHiddenWindows, on
hw_ahk := WinExist("ahk_pid " DllCall("GetCurrentProcessId"))
DetectHiddenWindows, off
WM_WTSSESSION_CHANGE = 0x02B1
OnMessage( WM_WTSSESSION_CHANGE, "HandleMessage" )
NOTIFY_FOR_THIS_SESSION = 0
result := DllCall( "Wtsapi32.dll\WTSRegisterSessionNotification", "uint", hw_ahk, "uint", NOTIFY_FOR_ALL_SESSIONS )
return
HandleMessage( p_w, p_l, p_m, p_hw )
{
if ( p_w = 0x7 )
{
SetNumLockState, Off
}
else if ( p_w = 0x8 )
{
SetNumLockState, On
}
}