有没有办法查看物理键盘是否连接到 Windows 8 设备?

有没有办法查看物理键盘是否连接到 Windows 8 设备?

问题描述:

我正在编写 Windows 8 游戏.游戏可在 Windows 7、Windows Phone 和 XBox 上运行.

I'm writing a Windows 8 game. The game runs on Windows 7, Windows Phone, and XBox.

如果连接了键盘,我想显示键盘提示(例如按 Esc 退出")

I want to display keyboard hints if a keyboard is attached (e.g. 'Press Esc to exit')

鉴于 Windows 8 可以是台式机、笔记本电脑或平板电脑,因此可能有也可能没有连接物理键盘.有没有办法以编程方式确定这一点?

Seeing as Windows 8 can be a desktop, laptop, or tablet, there may or may not be a physical keyboard attached. Is there a way to determine this programmatically?

当然,请在此处

private void GetKeyboardProperties()
{
    KeyboardCapabilities keyboardCapabilities = new Windows.Devices.Input.KeyboardCapabilities();
    KeyboardPresent.Text = keyboardCapabilities.KeyboardPresent != 0 ? "Yes" : "No";
}

或者如果您是 html5/js 开发人员,请查看此处.

or if you html5/js developer take a look here.