Skip to content

Commit 95d4dbf

Browse files
committed
Added WM_DEVICECHANGE
1 parent 10f97a0 commit 95d4dbf

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

src/messages/WM_DEVICECHANGE.ahk

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
; GLOBAL SETTINGS ===============================================================================================================
2+
3+
#NoEnv
4+
#Persistent
5+
#SingleInstance Force
6+
SetBatchLines -1
7+
8+
OnMessage(0x0219, "WM_DEVICECHANGE")
9+
10+
; SCRIPT ========================================================================================================================
11+
12+
; ....
13+
14+
; FUNCTIONS =====================================================================================================================
15+
16+
WM_DEVICECHANGE(wParam, lParam)
17+
{
18+
static init := OnMessage(0x0219, "WM_DEVICECHANGE")
19+
if (wParam = 0x8000) || (wParam = 0x8004) && ((NumGet(lParam+4, "UInt")) = 0x2) {
20+
i := 0, mask := NumGet(lParam+12, "UInt")
21+
while (mask > 1) && (++i < 0x1A)
22+
mask >>= 1
23+
DeviceChangeInfo(Chr(0x41 + i) ":\", wParam)
24+
}
25+
}
26+
27+
DeviceChangeInfo(device, state)
28+
{
29+
MsgBox, 0x40, % "Device Change", % device " " ((state = 0x8000) ? "plugged in" : (state = 0x8004) ? "is removed" : ""), 2
30+
}
31+
32+
; ===============================================================================================================================
33+
34+
/*
35+
https://msdn.microsoft.com/en-us/library/aa363480(v=vs.85).aspx WM_DEVICECHANGE message
36+
https://msdn.microsoft.com/en-us/library/aa363205(v=vs.85).aspx DBT_DEVICEARRIVAL event
37+
https://msdn.microsoft.com/en-us/library/aa363208(v=vs.85).aspx DBT_DEVICEREMOVECOMPLETE event
38+
https://msdn.microsoft.com/en-us/library/aa363246(v=vs.85).aspx DEV_BROADCAST_HDR structure
39+
https://msdn.microsoft.com/en-us/library/aa363249(v=vs.85).aspx DEV_BROADCAST_VOLUME structure
40+
*/

0 commit comments

Comments
 (0)