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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:11:57+00:00 2026-05-26T23:11:57+00:00

So in the text editor program that i’ve been working on, I’ve used WM_CHAR

  • 0

So in the text editor program that i’ve been working on, I’ve used WM_CHAR to process input from the keyboard. However, I found that some of the character mesages are not recorded. For example, if I use [shift]+ number key to type a symbol such as % or &, some re recorded while others such as [shift]+9 (which results in ‘)’), are not recorded. So, I’m wondering if I should use WM_KEYDOWN/WMKEYUP pair to handle keyboard input. I once wrote a keylogger in assembly(actually it was just a tutorial that i was trying out) and had used WM_KEYDOWN/WM_KEYUP pairs and that worked out quite good. So, should I move on to this, or is it something unusual that is happening with my program?

Thanks,

Devjeet

  • 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-26T23:11:57+00:00Added an answer on May 26, 2026 at 11:11 pm

    This is really a long reply to your comment above, but putting it in an answer because it’s too long for a comment 🙂

    The core issue to understand here is that keys and characters are not quite the same thing. Some (but not all) keys generate characters; some keys generate different characters depending on shift or other keyboard state. And to implement an editor, you need to handle both textual input and also non-textual keyboard input like arrow keys. Now the long-winded version, picking off from what seems to be an incorrect assumption:

    Apparently, windows works in really strange ways. […] It seems that when you press [shift]+9, windows sends a VK_LEFT in the wParam of message WM_CHAR

    Sounds like you might be mixing two things up here. The thing with WM_CHAR is that it gives you character codes for textual characters: so if someone presses the 9 key, you’ll get ‘9’. If someone presses SHIFT+9, Windows will take the shift state into account – and you get ‘(‘ (if using US keyboard). But you won’t ever get a WM_CHAR for arrow keys, HOME, END, and so on, since they are not textual characters. WM_KEYDOWN, on the other hand, does not deal in characters, but in VK_ codes; so pressing 9 gives you VK_9 regardless of shift state; and left arrow gives you VK_LEFT – again regardles of shift state.

    The things is that WM_CHAR and WM_KEYDOWN both give you two parts to the overall input picture – but you really have to handle both to get the full picture. And have to be aware that the wParam is a very different thing in both cases. It’s a character code for WM_CHAR, but a VK_ code for WM_KEYDOWN. Don’t mix the two.

    And to make things more confusing, VK_ values share the same values as valid characters. Open up WinUser.h (it’s in the include dir under the compiler installation dir), and look for VK_LEFT:

    #define VK_LEFT           0x25
    

    Turns out that 0x25 is also the code for the ‘%’ character (see any ascii/unicode table for details). So if WM_CHAR gets 0x25, it means shift-5 was pressed (assuming US keyboard) to create a ‘%’; but if WM_KEYDOWN gets 0x25, it means left arrow (VK_LEFT) was pressed. And to add a bit more confusion, the Virtual Key codes for the A-Z keys and 0-9 keys happen to be the same as the ‘A’-‘Z’ and ‘0’-‘9’ characters – which makes it seem like chars and VK_’s are interchangable. But they’re not: the code for lower case ‘a’, 0x61, is VK_NUMPAD1! (So getting 0x61 in WM_CHAR does mean ‘a’, getting it in WM_KEYDOWN means NUMPAD1. And if a user does hit the ‘A’ key in unshifted state, what you actually get is first a VK_A (same value as ‘A’) in WM_KEYDOWN, which gets translated to WM_CHAR of ‘a’.)

    So tying all this together, the typical way to handle keyboard is to use all of the following:

    • Use WM_CHAR to handle textual input: actual text keys. wParam is the character that you want to append to your string, or do whatever else with. This does all the shift- processing for you.

    • Use WM_KEYDOWN to handle ‘meta’ keys – like arrow keys, home, end, page up, and so on. Pass all the A-Z/0-9 values through, the default handling will turn them into WM_CHARs that you can handle in your WM_CHAR handler. (You can also handle numpad keys here if you want to use them for special functionality; otherwise they ‘fall through’ to end up as numeric WM_CHARs, depending on numlock state. Windows takes care of this, just as it handles shift state for the alphabetic keys.)

    • If you want to handle ALT- combos explicitly (rather than using an accelerator table), you’ll get those via WM_SYSKEYDOWN.

    I think there are some keys that might show up in both – Enter might show up as both a WM_KEYDOWN of VK_RETURN and as either \r or \n WM_CHAR – but my preference would be to handle it in WM_KEYDOWN, to keep editing key handling separate from text keys.

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

Sidebar

Related Questions

For a rich text editor that has to handle pasted HTML code from MS
I want to make a program that's like a simple text editor using Qt
I have been able to write a program that can read any text files...
I need to write a simple terminal-based program that should, Read some text from
I've been looking for an IDE or Text Editor that can save snapshots of
Ok, I'm writing a program in vb. It's simply a text editor. However i've
I have a text editor I made, which has been working perfectly for the
I've been working on a text editor for some time. I made a custom
Hi I have text editor widget in smalltalk (visual works) that returns a text
i've been working on 2 projects, a program made in Game Maker 8 and

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.