After looking at Sean's script I see he was using the initial call to get keyboard state as a save to be restored on program exit. Since the user may change the state of num lock or caps lock while the program is running, I thought it better to only save the Scroll Lock state, since that's what this program changes.
All my mods are commented. This script has them all incorporated along with code that saves and restores just the state of the scroll lock.
I named it HDDMonitorMAmod.ahk to avoid confusion.
http://www.autohotkey.net/~MilesAhead/Scripts/HDDMonitorMAmod.zip
Code:
;HDDMonitorMAmod.ahk
#Persistent
#SingleInstance, Force
SetBatchLines, -1
;Run, diskperf.exe -y ; Execute it once to enable Disk Performance monitoring.
OnExit, ExitLED
;save a bit on memory if Windows 5 or newer - MilesAhead
result := DllCall("psapi.dll\EmptyWorkingSet", "Int", -1, "Int")
SetTimer, StartLED, On, 500
hDrive := DllCall("CreateFile", "str", "\\.\PhysicalDrive0", "Uint", 0, "Uint", 3, "Uint", 0, "Uint", 3, "Uint", 0, "Uint", 0)
hKeybd := DllCall("CreateFile", "str", "\\.\GLOBALROOT\Device\KeyboardClass0", "Uint", 0, "Uint", 3, "Uint", 0, "Uint", 3, "Uint", 0, "Uint", 0)
DllCall("DeviceIoControl", "Uint", hKeybd, "Uint", 0x000B0040, "Uint", 0, "Uint", 0, "UintP", _nStatus_, "Uint", 4, "UintP", nReturn, "Uint", 0) ; IOCTL_KEYBOARD_QUERY_INDICATORS
;only save Scroll Lock status since caps lock or
;num lock may be changed by the user while this is running - MilesAhead
scrollOn := _nStatus_ & 1 << 16
Return
StartLED:
VarSetCapacity(dp, 88)
DllCall("DeviceIoControl", "Uint", hDrive, "Uint", 0x00070020, "Uint", 0, "Uint", 0, "Uint", &dp, "Uint", 88, "UintP", nReturn, "Uint", 0) ; IOCTL_DISK_PERFORMANCE
nReadCount := NumGet(dp, 40)
nWriteCount := NumGet(dp, 44)
;get keyboard status again
DllCall("DeviceIoControl", "Uint", hKeybd, "Uint", 0x000B0040, "Uint", 0, "Uint", 0, "UintP", _nStatus_, "Uint", 4, "UintP", nReturn, "Uint", 0) ; IOCTL_KEYBOARD_QUERY_INDICATORS
;to above comment is my mod - MilesAhead
If (nWriteCount <> _nWriteCount_) || (nReadCount <> _nReadCount_)
{
_nReadCount_ := nReadCount
_nWriteCount_ := nWriteCount
nStatus := _nStatus_ | 1 << 16
}
Else nStatus := _nStatus_ & ~(1 << 16)
DllCall("DeviceIoControl", "Uint", hKeybd, "Uint", 0x000B0008, "UintP", nStatus, "Uint", 4, "Uint", 0, "Uint", 0, "UintP", nReturn, "Uint", 0)
Return
ExitLED:
SetTimer, StartLED, Off
;restore original Scroll Lock state - MilesAhead
If scrollOn
nStatus := _nStatus_ | 1 << 16
Else
nStatus := _nStatus_ & ~(1 << 16)
DllCall("DeviceIoControl", "Uint", hKeybd, "Uint", 0x000B0008, "UintP", nStatus, "Uint", 4, "Uint", 0, "Uint", 0, "UintP", nReturn, "Uint", 0) ; IOCTL_KEYBOARD_SET_INDICATORS
DllCall("CloseHandle", "Uint", hKeybd)
DllCall("CloseHandle", "Uint", hDrive)
ExitApp