【问题标题】:Is there a way to see if a physical keyboard is attached to a Windows 8 device?有没有办法查看物理键盘是否连接到 Windows 8 设备?
【发布时间】:2013-01-01 18:35:12
【问题描述】:

我正在编写一个 Windows 8 游戏。该游戏可在 Windows 7、Windows Phone 和 XBox 上运行。

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

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

【问题讨论】:

标签: windows-8


【解决方案1】:

当然, 请阅读此快速入门here

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

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

【讨论】:

  • 如何在 VS2012 .net 2 中访问它?
  • 仅供参考,这仅适用于 Windows 应用商店应用。如果您在常规桌面上运行,您将无法访问此 API。
  • 如果您引用Windows.Foundation.UniversalApiContract,您确实可以从桌面应用程序访问,API 不限于存储应用程序容器。但无论如何它都不能正常工作,如果没有连接键盘,它会在 Surface 4 Pro 平板电脑上报告为“是”。
猜你喜欢
  • 2011-02-11
  • 1970-01-01
  • 2018-11-20
  • 1970-01-01
  • 2011-11-09
  • 1970-01-01
  • 2023-03-10
  • 2013-05-20
  • 2011-02-15
相关资源
最近更新 更多