Windows 8.1 Handling Physical Keyboard Input RRS feed

  • Question

  • I'm developing a Universal App in c# for Windows 8.1

    I'm trying to catch keyboard input and from the on-line literature have been pointed to KeyDown event and KeyRoutedEventArgs and the Key property.  This works fine for most key characters and returns VirtualKey enumerations such as VirtualKey.A.  However, when characters such as ,.;:><?' are pressed the Key property is set to a number and this number is the same value if the key is pressed in combination with VirtualKey.Shift which seems to indicate it is not representative of the characters on the key, but only represents the physical key.

    As it happens, I'm using an Italian laptop keyboard which of course is laid out differently to a UK Extended keyboard so the Key value for a semicolon (;) is 186 on a UK keyboard (as an un-Shifted or bottom character) and is 188 on an Italian keyboard (as a Shift or top character).  I'm therefore stumped as far a capturing these punctuation characters.

    I have developed WPF, Silverlight and .Net app in the past and don't remember it being as difficult to handle physical keyboard input even in combination a game loop, as I just used the Key or Keys enumeration and an OEM value.

    How can I capture these punctuation characters when their respective key is pressed, irrespective of the keyboard layout?


    Wednesday, October 22, 2014 8:30 PM


  • It's not clear exactly what you are looking for here, but you have two options:

    1) Watch for virtual keys. As you note, these match up to the unmodified key position, not to specific characters. You won't get different values for the shifted and unshifted state of a key and you can't match a VK to a specific character without knowing the keyboard layout and state.

    2) Watch for characters with CoreWindow.CharacterReceived. This will return the encoded character based on the keyboard state and layout.

    Usually for games you want the former and need to have different versions for different languages. Letting users choose their own keyboard mappings can be a good feature.


    Thursday, October 23, 2014 2:19 AM