Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4534900
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:20:18+00:00 2026-05-21T14:20:18+00:00

I started making use of Win32’s raw input features to detect all keys on

  • 0

I started making use of Win32’s raw input features to detect all keys on the keyboard. So far, everything is working great! I can distinguish between numbers on the top row and numbers in the keypad on the right. I can even detect between the left and right shift keys. However, the control and alt keys do not return unique scan codes. The control key returns 29, and the alt key returns 56.

The popular method for checking key states on these keys is GetAsyncKeyState. I have tested that function using VK_LCONTROL and VK_RCONTROL, and it works, but that only helps me for capturing key down events. I would really like to be able to capture key up events as well. It is obvious that the API is somehow aware of which key is being pressed; how do I get ahold of that information?

I am currently extracting the scan code from the RAWKEYBOARD structure’s MakeCode field. That gives me information about every key (and its left/right alignment) except CTRL and ALT. How would I go about capturing the key up events (and knowing whether it is left/right)? Is it possible using just the RAWKEYBOARD structure? Or do I have to concoct some kind of workaround?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T14:20:19+00:00Added an answer on May 21, 2026 at 2:20 pm

    If you want to get low level enough to detect key up events, you should process the WM_KEYDOWN and WM_KEYUP events:

    • http://msdn.microsoft.com/en-us/library/ms646267%28v=vs.85%29.aspx#_win32_Keystroke_Messages

    Pressing a key causes a WM_KEYDOWN or
    WM_SYSKEYDOWN message to be placed in
    the thread message queue attached to
    the window that has the keyboard
    focus. Releasing a key causes a
    WM_KEYUP or WM_SYSKEYUP message to be
    placed in the queue.

    Key-up and key-down messages typically
    occur in pairs, but if the user holds
    down a key long enough to start the
    keyboard’s automatic repeat feature,
    the system generates a number of
    WM_KEYDOWN or WM_SYSKEYDOWN messages
    in a row. It then generates a single
    WM_KEYUP or WM_SYSKEYUP message when
    the user releases the key.

    To distinguish between the left and right versions of the Shift, Ctrl, or Alt keys, you have to use the MapVirtualKey() function or the ‘extended key’ bit in the lParam passed with the virtual key’s message. The following function will perform that translation for you – just pass in the virtual keycode and the lParam from the message, and you’ll get back the left/right specific virtual keycodes as appropriate:

    WPARAM MapLeftRightKeys( WPARAM vk, LPARAM lParam)
    {
        WPARAM new_vk = vk;
        UINT scancode = (lParam & 0x00ff0000) >> 16;
        int extended  = (lParam & 0x01000000) != 0;
    
        switch (vk) {
        case VK_SHIFT:
            new_vk = MapVirtualKey(scancode, MAPVK_VSC_TO_VK_EX);
            break;
        case VK_CONTROL:
            new_vk = extended ? VK_RCONTROL : VK_LCONTROL;
            break;
        case VK_MENU:
            new_vk = extended ? VK_RMENU : VK_LMENU;
            break;
        default:
            // not a key we map from generic to left/right specialized
            //  just return it.
            new_vk = vk;
            break;    
        }
    
        return new_vk;
    }
    

    If the virtual keycode passed in isn’t one that maps to a left/right version, the original keycode is passed back unchanged. So you can just run the WM_KEYDOWN/WM_KEYUP/WM_SYSKEYDOWN/WM_SYSKEYUP message parameters through the function whenever you need to distinguish between the left and right variants.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a simple 2 player game in XNA and started looking into saving
I started a Rails project recently and decided to use RESTful controllers. I created
I started trying to play with Mono, mostly for fun at the moment. I
I started an application in Google App Engine right when it came out, to
I started using subversion for one of my projects and it would be absolutely
I started programming C# applications when the 1.0 framework was first released. I worked
I started off programming in Basic on the ZX81 , then BASICA , GW-BASIC
Just started getting a bunch of errors on our C# .Net app that seemed
I started dabbling in groovy yesterday. There's an example on the groovy website that
I started with jetlang and the basic samples are pretty clear. What I didn't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.