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.
In reply to Re^3: How do I know when a USB device is inserted?
by Corion
in thread How do I know when a USB device is inserted?
by ZJ.Mike.2009
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |