locked
Handling different keyboard layouts with WM_CHAR message? RRS feed

  • Question

  • We have an app that is using WM_CHAR messages for keyboard input.

    I have the "Lithuanian Standard" keyboard layout loaded onto my Windows 10. If I have that activated and type a w on my regular English keyboard into a windows text box, I get a ž character. But if I press the same w key in my app, I get the þ character instead.

    Is there a Windows API call I can make to have Windows turn the wchar_t þ I get from WM_CHAR into a ž based on the current keyboard layout? (and handle all the other situations as well)

    Our program is 100% Unicode enabled and our window is created with CreateWindowW and etc.

    Also we need to support as far back as Windows 7 only.

    • Edited by jonwil Monday, March 2, 2020 10:11 PM
    Monday, March 2, 2020 10:04 PM

All replies

  • IMHO, the best way to simulate keyboard input is to use the SendInput function.  This function inserts synthesized input into the keyboard input stream and so it will be handled by the system as if it was actually generated by the keyboard.  The synthesized input will be sent to the window that has the keyboard focus.

    For a brief discussion about why using WM_CHAR is not equivalent to actual keyboard input, see Simulating input via WM_CHAR messages may fake out the recipient but it won't fake out the input system


    • Edited by RLWA32 Tuesday, March 3, 2020 1:06 AM
    Tuesday, March 3, 2020 1:06 AM
  • Turns out that the cause of my problem was a bug that resulted in the main window being created as ANSI and not Unicode like I thought it was. Once that was fixed and the windows was switched to Unicode, I got the correct values in my WM_CHAR messages when I pressed different keys and had a foreign keyboard layout selected.

    Tuesday, March 3, 2020 8:09 PM