9

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

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

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?

Steve Dunn
  • 21,044
  • 11
  • 62
  • 87
  • possible duplicate of [Detect keyboard presence in Windows 8 desktop program](http://stackoverflow.com/questions/11993680/detect-keyboard-presence-in-windows-8-desktop-program) – Frank van Puffelen Jan 01 '13 at 18:42
  • It's not a dupe as this is for Store Apps, it's relevant however given people are bound to want this for Desktop apps – Jay Wick Mar 17 '15 at 10:34

1 Answers1

9

Of course, please read this quick start here

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

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

gniourf_gniourf
  • 44,650
  • 9
  • 93
  • 104
Taras Seredokha
  • 372
  • 1
  • 7
  • how do i access this in VS2012 .net 2? – f1wade Feb 03 '14 at 12:35
  • 5
    FYI this only applies to Windows Store apps. You won't have access to this API if you're running on the regular desktop. – donovan Sep 11 '14 at 00:54
  • You do have access from Desktop apps if you reference `Windows.Foundation.UniversalApiContract`, the API is not restricted to store app containers. But it doesn't work correctly anyways, it reports as 'Yes' on a surface 4 pro tablet if there is no keyboard attached. – Zarat Jun 28 '19 at 10:02