Answered by:
Event when Hardware is connected/disconnected? (Mouse/Keyboard)

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?
Thanks!
Tuesday, September 16, 2014 4:23 PM
Answers
-
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.
--Rob- Edited by Rob Caplan [MSFT]Microsoft employee, Moderator Wednesday, September 17, 2014 12:32 AM
- Marked as answer by Herro wongMicrosoft contingent staff, Moderator Monday, September 29, 2014 1:27 AM
Tuesday, September 16, 2014 4:54 PMModerator
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 PMModerator -
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.
--Rob- Edited by Rob Caplan [MSFT]Microsoft employee, Moderator Wednesday, September 17, 2014 12:32 AM
- Marked as answer by Herro wongMicrosoft contingent staff, Moderator Monday, September 29, 2014 1:27 AM
Tuesday, September 16, 2014 4:54 PMModerator