I need to implement certain functions only when the keyboard is attached to the surface. Is there a way I can detect when the surface keyboard is attached or removed ?
I tried this code on Surface:
function getKeyboardCapabilities()
{
var keyboardCapabilities = new Windows.Devices.Input.KeyboardCapabilities();
console.log(keyboardCapabilities.keyboardPresent);
}
The result was always '1' even when the keyboard was not connected.
I used this code to identify when a keyboard is connected to a Surface:
Then call
KeyboardWatcher.isAttached()
whenever you need to check the status of the keyboard.I could not find a good way to detect if a keyboard is attached so instead I detect if I am in tablet mode or desktop mode.
Note the other possible value of uiMode is Windows.UI.ViewManagement.UserInteractionMode.Touch.