tags:

views:

280

answers:

2

Can windows detect when a monitor, mouse or keyboard is disconnected from the computer? If so what Win32 API is used for this?

+3  A: 

Not sure about the monitor, but the keyboard and mouse being disconnected should fire off a WM_DEVICECHANGE message if they are USB devices. See this link for details: WM_DEVICECHANGE

There is a good discussion of WM_DEVICECHANGE on this forum, relating to its usage with HID devices (Mouse/Keyboard/etc.)

For more detailed notification you can use the RegisterDeviceNotification function RegisterDeviceNotification

John Sibly
A: 

As far as I recall there is no way to detect PS/2 disconnection events. Monitor and USB can be trapped but I don't know how.

Cem Kalyoncu
Well, PS/2 has no disconnection events because it simply doesn't support getting unplugged while in use. And this can fry your controller if you do it :-)
Joey