locked
Hardware Keyboard Events for Windows Store App C# RRS feed

  • Question

  • I am creating a Windows Store App with C# and I would like to allow the user to use their hardware keyboard to type letters for my spelling game app. How do I capture the key (keycode) the user has pressed?
    Monday, January 27, 2014 2:47 PM

Answers

  • Depending on what exactly you need either look for KeyUp/KeyDown events (key codes) or CharacterReceived (characterd) events. For a spelling game you probably want characters.
    Monday, January 27, 2014 5:37 PM
    Moderator

All replies

  • Depending on what exactly you need either look for KeyUp/KeyDown events (key codes) or CharacterReceived (characterd) events. For a spelling game you probably want characters.
    Monday, January 27, 2014 5:37 PM
    Moderator
  • Depending on what exactly you need either look for KeyUp/KeyDown events (key codes) or CharacterReceived (characterd) events. For a spelling game you probably want characters.

    I researched both of those events and this is what I found,

    http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.core.characterreceivedeventargs.aspx

    http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.core.characterreceivedeventargs.keycode.aspx

    http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.core.characterreceivedeventargs.keycode.aspx

    and

    http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.core.characterreceivedeventargs.handled.aspx

    Can you tell me if this is what I can use?

    Tuesday, January 28, 2014 2:52 PM
  • Yes, you can subscribe to the CharacterReceived event which will be called with the CharacterReceivedEventArgs.

    Also consider using a TextBox rather than handling keyboard input directly. This will work better with alternate input types (such as IMEs and Inking) and will provide appropriate accessibility information without custom coding on your part.

    --Rob

    Saturday, February 1, 2014 7:42 AM
    Moderator