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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T18:11:41+00:00 2026-05-21T18:11:41+00:00

My WPF application handles keyboard presses and specifically the # and * character as

  • 0

My WPF application handles keyboard presses and specifically the # and * character as it is a VoIP phone.

I have a bug though with international keyboards, and in particular the British english keyboard. Normally I listen for the 3 key and if the shift key modifier is down we fire off an event to do stuff. However on the British keyboard this is the ‘£’ character. I found that the UK english keyboard has a dedicated key for ‘#’. Obviously we could just listen for that particular key, but that doesn’t solve the case for US english which is shift-3 and all the countless other keyboards that put it somewhere else.

Long story short, how do I listen for a particular character from a key press, whether it’s a key combo or single key and react to it?

  • 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-21T18:11:42+00:00Added an answer on May 21, 2026 at 6:11 pm

    The function below, GetCharFromKey(Key key) will do the trick.

    It uses a series of win32 calls to decode the key pressed:

    1. get the virtual key from WPF key

    2. get the scan code from the virtual key

    3. get your unicode character

    This old post describes it in a bit more detail.

          public enum MapType : uint
          {
             MAPVK_VK_TO_VSC = 0x0,
             MAPVK_VSC_TO_VK = 0x1,
             MAPVK_VK_TO_CHAR = 0x2,
             MAPVK_VSC_TO_VK_EX = 0x3,
          }
    
          [DllImport("user32.dll")]
          public static extern int ToUnicode(
              uint wVirtKey,
              uint wScanCode,
              byte[] lpKeyState,
              [Out, MarshalAs(UnmanagedType.LPWStr, SizeParamIndex = 4)] 
                StringBuilder pwszBuff,
              int cchBuff,
              uint wFlags);
    
          [DllImport("user32.dll")]
          public static extern bool GetKeyboardState(byte[] lpKeyState);
    
          [DllImport("user32.dll")]
          public static extern uint MapVirtualKey(uint uCode, MapType uMapType);
    
          public static char GetCharFromKey(Key key)
          {
             char ch = ' ';
    
             int virtualKey = KeyInterop.VirtualKeyFromKey(key);
             byte[] keyboardState = new byte[256];
             GetKeyboardState(keyboardState);
    
             uint scanCode = MapVirtualKey((uint)virtualKey, MapType.MAPVK_VK_TO_VSC);
             StringBuilder stringBuilder = new StringBuilder(2);
    
             int result = ToUnicode((uint)virtualKey, scanCode, keyboardState, stringBuilder, stringBuilder.Capacity, 0);
             switch (result)
             {
                case -1: 
                   break;
                case 0: 
                   break;
                case 1:
                   {
                      ch = stringBuilder[0];
                      break;
                   }
                default:
                   {
                      ch = stringBuilder[0];
                      break;
                   }
             }
             return ch;
          }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For my WPF application I have developed a virtual keyboard. It runs fine on
I have a simple WPF application that uses ClickOnce to handle installing. Within this
I have a simple WPF application which I am trying to start. I am
I have a WPF application in VS 2008 with some web service references. For
My .NET 4 application uses the WPF TreeView which I have enhanced to enable
I seem to be going round in circles. I have a WPF application that
I have a simple WPF windows application trying to read a serial port with
I have a small WPF application. This application has a button that when clicked,
I've read up on how WPF handles the shutdown event. http://msdn.microsoft.com/en-us/library/system.windows.application.shutdownmode.aspx However in my
I have a WPF application that uses a custom window frame. My problem is

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.