I need when I plug in a specific USB device {do something}, and when I plug out that USB {do something}.
I searched a lot in the forums before I asked for a help, and the closest code I found for what I need was this:
Code: Select all
OnMessage(0x219, "WM_DEVICECHANGE")
return
EventHandler(letter, event)
{
if event
{
SoundBeep
SoundBeep
}
else
{
SoundBeep
}
}
WM_DEVICECHANGE(wp, lp)
{
static DBT_DEVICEARRIVAL := 0x8000, DBT_DEVICEREMOVECOMPLETE := 0x8004, DBT_DEVTYP_VOLUME := 2
if NumGet(lp + 4, "UInt") = DBT_DEVTYP_VOLUME && (wp = DBT_DEVICEARRIVAL || wp = DBT_DEVICEREMOVECOMPLETE) {
dbcv_unitmask := NumGet(lp + 12, "UInt")
letter := Chr(Asc("A") + ln(dbcv_unitmask)/ln(2))
timer := Func("EventHandler").Bind(letter, wp = DBT_DEVICEARRIVAL)
SetTimer, % timer, -10
}
}
I want it only to make the SoundBeep on a specific usb device that I changed it's drive letter to "S" in Disk Management.
Thankyou !!