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

  • Home
  • SEARCH
  • 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 3348542
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:33:19+00:00 2026-05-18T01:33:19+00:00

On MSDN, for the WM_KEYDOWN defition it says the bits of lparam contain: Bits

  • 0

On MSDN, for the WM_KEYDOWN defition it says the bits of lparam contain:

Bits    Meaning
0-15    The repeat count for the current message. The value is the number of times the keystroke is autorepeated as a result of the user holding down the key. If the keystroke is held long enough, multiple messages are sent. However, the repeat count is not cumulative.
16-23   The scan code. The value depends on the OEM.
24  Indicates whether the key is an extended key, such as the right-hand ALT and CTRL keys that appear on an enhanced 101- or 102-key keyboard. The value is 1 if it is an extended key; otherwise, it is 0.
25-28   Reserved; do not use.
29  The context code. The value is always 0 for a WM_KEYDOWN message.
30  The previous key state. The value is 1 if the key is down before the message is sent, or it is zero if the key is up.
31  The transition state. The value is always 0 for a WM_KEYDOWN message.

(http://msdn.microsoft.com/en-us/library/ms646280%28VS.85%29.aspx)

So i created a union with a struct inside like this:

union KeyState
{
    LPARAM lparam;

    struct
    {
        unsigned nRepeatCount : 15;
        unsigned nScanCode : 8;
        unsigned nExtended : 1;
        unsigned nReserved : 4;
        unsigned nContext : 1;
        unsigned nPrev : 1;
        unsigned nTrans : 1;
    };
};

Then when i recieve a wm_keydown message on my edit box, i print it like this:

if (msg == WM_KEYDOWN)
{
    std::tstringstream ss;

    KeyState ks;
    ks.lparam = lparam;

    ss << "Key: " << (TCHAR)wparam << ", Val: " << (UINT)wparam << ", nRepeatCount: " << ks.nRepeatCount << 
        ", nScanCode: " << ks.nScanCode << ", nExtended: " << ks.nExtended << ", nReserved: " << ks.nReserved << 
        ", nContext: " << ks.nContext << ", nPrev: " << ks.nPrev << ", nTrans: " << ks.nTrans;

    SetWindowText(hOut, ss.str().c_str());
}

The values that i get back when i’m typing in my edit box don’t seem correct, sometimes the nReserved is even 1 or 0, and nRepeatCount is ALWAYS 1 no matter if i hold down the key for a logn time or just press random keys.

Have i done something wrong? if so whats the ideal way to get these values from the LPARAM?

  • 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-18T01:33:20+00:00Added an answer on May 18, 2026 at 1:33 am

    Well, for one thing 0-15 is 16 bits, not 15.

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

Sidebar

Related Questions

The MSDN site says: From your view class's function that handles the WM_CREATE message
I am examining the value of a LPARAM when I receive the WM_KEYDOWN event.
How can a Win32 application respond to only the first WM_KEYDOWN notification? The MSDN
MSDN says that you should use structs when you need lightweight objects. Are there
MSDN docs say that only value types need boxing, but this does not apply
MSDN says that public static members of System.Windows.Application are thread safe. But when I
MSDN says http://msdn.microsoft.com/en-us/library/ms256086.aspx degree[@from != Harvard] - All elements where the from attribute is
MSDN documentation says The Show Data Sources command is only available in projects that
When typing into a CRichEditCtrl, EN_CHANGE messages are generated. However MSDN says: Rich Edit:
MSDN says that after CryptVerifySignature() you cannot reuse HCRYPTHASH object to try hashing more

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.