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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:46:05+00:00 2026-05-27T10:46:05+00:00

I’m experimenting with Application.AddMessageFilter , using some code written originally by Somebody Else, so

  • 0

I’m experimenting with Application.AddMessageFilter, using some code written originally by Somebody Else, so I don’t necessarily understand everything that’s happening here.

Here’s what the code looks like. In Main():

Application.AddMessageFilter(new KeyDownMessageFilter());

In KeyDownMessageFilter:

internal class KeyDownMessageFilter : IMessageFilter {
    private const int WM_KEYDOWN = 0x0100;

    public bool PreFilterMessage(ref Message m)
    {
        if (m.Msg == WM_KEYDOWN)
        {
            var k = (Keys)m.WParam;
            var c = (char)k;
            // and some other stuff
        }
        return false;
    }
}

I can see that by casting m.WParam to a variable of type System.Windows.Forms.Keys and then casting that to a char, I can tell which key on the keyboard was pushed. So far, so good.

BUT – I cannot work out how to tell the difference between a Shifted key and a key push without a Shift – e.g. pushing % yields the character ‘5’. Even more weirdly, looking at the value of the k, it appears as “LButton | MButton | ShiftKey | Space” (no matter whether I push 5 or %).

The MSDN documentation on this subject is rather thin. Can anyone please explain how to tell exactly what character was pushed, and for bonus marks, explain what this Message object is supposed to be for, and why it uses such nondescript properties such as LParam and WParam to carry useful information?

  • 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-27T10:46:06+00:00Added an answer on May 27, 2026 at 10:46 am

    e.g. pushing “%” yields the character ‘5’

    By design, the WM_KEYDOWN message passes a virtual key code in wparam. The virtual key code for the key that produces ‘%’ and ‘5’ is the same, it is the same key on your keyboard. It doesn’t get turned into an actual typing key until Windows processes the WM_KEYDOWN message and turns it into a WM_CHAR message. Which will check the state of the Shift, Ctrl and Alt keys and change the generated character accordingly. The actual character that is produced depends on the active keyboard layout.

    looking at the value of the k, it appears as “LButton | MButton | ShiftKey | Space”

    That’s a side-effect of the [Flags] attribute on the Keys type. The default Enum.ToString() method checks that attribute and will combine enum values if that attribute is present. The integer value of Keys.D5 is 0x35, a combination of 0x01 + 0x04 + 0x10 + 0x20. Respectively Keys.LButton, MButton, ShiftKey and Space. Clearly this is unhelpful in your case, cast to (int) in the watch expression.

    Well, that explains what is going on. The one thing you really want to avoid is trying to translate the virtual key to a typing key yourself. Have a look at the ToUnicodeEx() Windows api function, the one you have to use to do it properly. You can use the Control.ModifierKeys property to detect the difference between a plain Keys.D5 and one that’s pressed with the Shift key down.

    Btw: you should also trap WM_SYSKEYDOWN, the message that’s generated when the Alt key is down. Message 0x104.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

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.