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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:06:37+00:00 2026-05-11T12:06:37+00:00

If I know that a certain key has been pressed (eg Key.D3 ), and

  • 0

If I know that a certain key has been pressed (eg Key.D3), and that the Shift key is also down (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift)), how can I find out what character that refers to (eg, # on US keyboard, UK pound sign on UK keyboard, etc)?

Put another way, how can I find out, programatically, that Shift + 3 produces # (it wouldn’t on a non-US keyboard).

  • 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. 2026-05-11T12:06:37+00:00Added an answer on May 11, 2026 at 12:06 pm

    If you want to determine what character you will get from a given key with given modifiers, you should use the user32 ToAscii function. Or ToAsciiEx if you want to use a keyboard layout other then the current one.

    using System.Runtime.InteropServices; public static class User32Interop {   public static char ToAscii(Keys key, Keys modifiers)   {     var outputBuilder = new StringBuilder(2);     int result = ToAscii((uint)key, 0, GetKeyState(modifiers),                          outputBuilder, 0);     if (result == 1)       return outputBuilder[0];     else       throw new Exception('Invalid key');   }    private const byte HighBit = 0x80;   private static byte[] GetKeyState(Keys modifiers)   {     var keyState = new byte[256];     foreach (Keys key in Enum.GetValues(typeof(Keys)))     {       if ((modifiers & key) == key)       {         keyState[(int)key] = HighBit;       }     }     return keyState;   }    [DllImport('user32.dll')]   private static extern int ToAscii(uint uVirtKey, uint uScanCode,                                     byte[] lpKeyState,                                     [Out] StringBuilder lpChar,                                     uint uFlags); } 

    You can now use it like this:

    char c = User32Interop.ToAscii(Keys.D3, Keys.ShiftKey); // = '#' 

    If you need more than one modifier, just or them. Keys.ShiftKey | Keys.AltKey

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

Sidebar

Related Questions

I know that I can do something like $int = (int)99; //(int) has a
I know that the compiler will sometimes initialize memory with certain patterns such as
I know that in Jsoup when you want to find a certain Element with
I would like to know the paths of certain files that a user is
I know that you can insert multiple rows at once, is there a way
I know that the MsNLB can be configured to user mulitcast with IGMP. However,
I know this question has been asked to death here, but I am unable
A digital certificate is a digital document that certifies that a certain public key
I know that key-value pairs aren't good database design, aren't normalized etc however in
I know that default cron's behavior is to send normal and error output to

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.