Event when Hardware is connected/disconnected? (Mouse/Keyboard) RRS feed

  • Question

  • Hi,

    I would like to listen to hardware events, e.g. when a external mouse or keyboard is connected or disconnected.

    For example, I would like to change the UI when a Touch/Type cover of a Surface is connected to deliver a more mouse/keyboard centric UI instead of touch. Is it possible to listen to such an event? If yes, which one is it?


    Tuesday, September 16, 2014 4:23 PM


All replies

  • In general you're better off basing the UI on what the user is doing rather than what they have connected: If you get touch input then show touch UI. I'd you get more input then show mode UI. This is how standard controls such as ScrollViewers work.

    Often a system will still have the alternate devices connected even if the user isn't actively using them. Keyboard can be folded away, set aside, etc.

    Tuesday, September 16, 2014 4:40 PM
  • Hi, thanks for the reply!

    I'm already dynamically reacting to user input, i.e. switching to touch mode when touch is invoked and mouse when the mouse is used.

    I'd still like to react to connect/disconnect events because I think it would make for a cool and delightful feature. Is there an API for something like this or not?

    Tuesday, September 16, 2014 4:43 PM
  • See http://msdn.microsoft.com/en-us/library/windows/apps/xaml/Hh868250(v=win.10).aspx and the DeviceWatcher class

    They don't always give expected results for keyboards since drivers often report present even when the keyboard isn't physically there.

    Tuesday, September 16, 2014 4:54 PM