in reply to Re^2: How do I know when a USB device is inserted?
in thread How do I know when a USB device is inserted?
Here's a working example:
#!perl -w use strict; use Win32::GUI (); use constant WM_DEVICECHANGE => 0x219; # as per http://msdn.microsoft.com/en-us/library/aa363480%28VS.85%29.a +spx sub device_changed { my ($win, @args) = @_; Win32::GUI::MessageBox(0,"Device changed: @args\n"); }; my $mw = Win32::GUI::Window->new(); $mw->Hook(WM_DEVICECHANGE, \&device_changed); $mw->Show(); Win32::GUI::Dialog(); print "Done\n";
A problem with this approach is that WM_DEVICECHANGE does not seem to fire if AutoPlay is disabled for devices, at least I don't get the message when I insert a CF card in my CF card reader, while I get the message when I plug/unplug some other device.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: How do I know when a USB device is inserted?
by ZJ.Mike.2009 (Scribe) on Mar 06, 2010 at 09:40 UTC | |
by Corion (Patriarch) on Mar 06, 2010 at 11:04 UTC | |
by ZJ.Mike.2009 (Scribe) on Mar 06, 2010 at 14:24 UTC |