locked
Need keyboard scan codes

    Question

  • Where can I find a list of keyboard scan codes for a WinRT app?  Even better, is there a system type that has them as Enum values?  I can't use MapVirtualKey() because it's a WinApi.  I found this document but amazingly it's a scan of a keyboard scan code table, not some code I could include in my project:

    http://msdn.microsoft.com/en-us/library/aa299374(v=vs.60).aspx


    -- roschler

    Saturday, March 08, 2014 7:49 PM

All replies

  • Capture the keydown event:

    void Renderer::keydown(KeyEventArgs^ args) { int aa=(int)args->VirtualKey;

    if ((int) args->VirtualKey == VK_RIGHT) //right


    {



    n.Wright


    • Edited by nigelwright7557 Saturday, March 08, 2014 9:30 PM
    • Proposed as answer by nigelwright7557 Saturday, March 08, 2014 9:32 PM
    • Unproposed as answer by roschler Saturday, March 08, 2014 11:13 PM
    Saturday, March 08, 2014 9:29 PM
  • Why do you need  this? What are you actually trying to achieve?

    The scan codes will be different on different keyboards. For most cases you probably need the character or the key rather than the scancode.

    --Rob

    Saturday, March 08, 2014 10:14 PM
    Owner
  • Hello Rob,

    I'm trying to react to different keystrokes for those people running my WinRT app on a desktop computer or other non-touch computer.  For example, hitting enter when in a text box triggers an operation normally triggered by a tap.  Other keystrokes I'll want to react to are ESC, TAB, etc.  Is there something better than the ScanCode property that comes back from the KeyUp event arguments?


    -- roschler

    Saturday, March 08, 2014 11:12 PM
  • What I'm asking for is the list of key codes.  That is, where did you get VK_RIGHT from and will it be the same across keyboards as Rob has pointed out below?

    -- roschler

    Saturday, March 08, 2014 11:13 PM
  • What I'm asking for is the list of key codes.  That is, where did you get VK_RIGHT from and will it be the same across keyboards as Rob has pointed out below?

    -- roschler

    Just look up windows 8 app keyboard codes.All the special keys have names like VK_RIGHT, VK_LEFT etc etc

    Otherwise the other keys are ASCII from 32  to 127


    n.Wright

    Saturday, March 08, 2014 11:16 PM
  • You want virtual keys, not scan codes. You can get their values from the VirtualKeys class.

    Nigel's code is for C++ not for C#. VK_RIGHT is from the equivalent from the desktop header files.

    Sunday, March 09, 2014 12:21 AM
    Owner