I used this code to identify when a keyboard is connected to a Surface:
var keyboardWatcher = (function () {
// private
var keyboardState = false;
var watcher = Windows.Devices.Enumeration.DeviceInformation.createWatcher();
watcher.addEventListener("added", function (devUpdate) {
// GUID_DEVINTERFACE_KEYBOARD
if ((devUpdate.id.indexOf('{884b96c3-56ef-11d1-bc8c-00a0c91405dd}') != -1) && (devUpdate.id.indexOf('MSHW0007') == -1) ) {
if (devUpdate.properties['System.Devices.InterfaceEnabled'] == true) {
// keyboard is connected
keyboardState = true;
}
}
});
watcher.addEventListener("updated", function (devUpdate) {
if (devUpdate.id.indexOf('{884b96c3-56ef-11d1-bc8c-00a0c91405dd}') != -1) {
if (devUpdate.properties['System.Devices.InterfaceEnabled']) {
// keyboard is connected
keyboardState = true;
}
else {
// keyboard disconnected
keyboardState = false;
}
}
});
watcher.start();
// public
return {
isAttached: function () {
return keyboardState;
}
}
})();
Then call KeyboardWatcher.isAttached()
whenever you need to check the status of the keyboard.
KeyboardCapabilities.KeyboardPresent
– BarrettbarretteKeyboardCapabilities.keyboardPresent
on a computer with a physical keyboard and the result was '1' which is good. However the same code on a Surface always returned '1' even when the keyboard was not attached. – Rifle