问题
We are using KeyboardCapabilities.KeyboardPresent to test if a keyboard is connected to a device:
bool hasKeyboard = new KeyboardCapabilities().KeyboardPresent == 1;
Unfortunately it's always TRUE regardless if a bluetooth keyboard is connected or not. We tried it with the following hardware:
Dell Vostro 470 is a desktop PC with wireless Bluetooth keyboard which has power ON/OFF options. http://www.dell.com/in/business/p/vostro-470/pd
Samsung 700T Notebook (Slate) http://www.samsung.com/uk/consumer/pc-peripherals/slate-pc/slate-pc/XE700T1A-A01UK
Switching off the keyboard, bluetooth, removing the keyboard from the devices list, etc. didn't help, KeyboardCapabilities.KeyboardPresent always returns 1.
Are we missing something here or is there an API which we should use instead to detect such changes?
回答1:
Also having this issue, on my Microsoft Surface(which has a detachable keyboard), the KeyboardPresent
always returns a '1', even if no keyboard(touch/type cover) is attached and we have the software keyboard open.
回答2:
I have the same behavior on my tablet. Might be a bug...
A more complex solution is to enumerate device containers. It will tell you if any keyboard is connected. For more details, refer to the Device enumeration sample.
来源:https://stackoverflow.com/questions/12841218/windows-8-winrt-keyboardcapabilities-keyboardpresent-is-always-true