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 7590509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:25:08+00:00 2026-05-30T20:25:08+00:00

According to this page on MSDN, the Key Value for Left Control is 162.

  • 0

According to this page on MSDN, the Key Value for Left Control is 162. How can I determine if this key is pressed in code? At the moment, everytime I try and handle a keypress, I get the value 17 which is just a generic control key. Is there a way to differentiate the two? I’ve tried overriding ProcessCmdKey and handling PreviewKeyDown of a Textbox, but they both return 17 instead of 162. I need to do this for all modifier keys and before I end up hardcoding the values, is there a better alternative to capture these in code?

Edit: Code added. To clarify, I want to retrieve the 162 number and not just find an alternative way of differentiating the modifiers.

private void PortfolioNameTextBox_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
    var val = e.KeyValue; //17 when control is pressed and not 162

}

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
    //msg.Wparam = 17
    return base.ProcessCmdKey(ref msg, keyData);
}
  • 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-30T20:25:10+00:00Added an answer on May 30, 2026 at 8:25 pm

    Messr Passant answered this many moons ago.

    Would be nice if the KeyEventArgs included it, but nonetheless, you can achieve it like this:

        [DllImport("user32.dll")]
        private static extern short GetAsyncKeyState(Keys key);
    
        private void textBox1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
        {
            Console.WriteLine("Ctrl:{0}, LCtrl:{1}, RCtrl:{2}",
            GetAsyncKeyState(Keys.ControlKey) < 0,
            GetAsyncKeyState(Keys.LControlKey) < 0,
            GetAsyncKeyState(Keys.RControlKey) < 0);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

according to this page one can't use code like if variable = something(): #do
According this MSDN article HttpApplication .EndRequest can be used to close or dispose of
According to this website , you can change to command key sequence used by
According to this MSDN page : WOW64 enables 32-bit applications to take advantage of
ANY DOM element can be made resizable according to this page: http://jqueryui.com/demos/resizable/ However, it
According to the last sentence on this MSDN page use is to be preferred
According to this page you can implicitly convert shared_ptr<Foo> to shared_ptr<const Foo> . That
According to this page navigating between highlighted usages: (source: jetbrains.com ) can be done
According to this page: http://jqueryui.com/demos/tabs/#ajax I can have the content of tabs in separate
According to this page in MSDN, turns out that the accessibility of a specific

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.