What’s wrong with TranslateMessage?  Two things:

  1. It probably shouldn’t be in the message loop.  Different windows do different things with character and keystroke messages.  Performance is not an issue here nowadays.  Having TranslateMessage in the message loop has resulted in awful things such as IsDialogMessage and TranslateAccelerator calls for every message that goes through the loop.
  2. More importantly though, TranslateMessage really should return TRUE if the keystroke message generates characters.  It should return FALSE in every other situation.  Unfortunately, TranslateMessage currently returns TRUE for WM_*KEYDOWN messages, even if no characters are generated by the keystroke (think F2 or Ctrl or up-arrow or Ctrl+Shift+X).  This means that application developers have no way of knowing if the key can be safely used as a shortcut key, or should be ignored because a WM_CHAR or similar is on its way to insert into the current focus.

    This in turn means that shortcut keys are typically processed (with TranslateAccelerator or a homegrown variety thereof) before TranslateMessage – and some characters are now inaccessible on some keyboard layouts.

    The typical workaround is to add a hack for Ctrl+Alt (AltGr).  Yuck.  And that doesn’t solve other supported combinations such as Ctrl+Shift.

So what’s the answer to these problems? TranslateMessageEx?

Categories: Developing Keyman

0 thoughts on “What’s wrong with TranslateMessage?”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Posts

Developing Keyman

Keyman Update for 23 May 2025

This blog reports on significant Keyman product and keyboard development updates over the period from 12 May 2025 — 23 May 2025. As always, you can follow all of our development online at github.com/keymanapp/keyman, and Read more…

Developing Keyman

Keyman Roadmap – May 2025

This is an update from our last Roadmap blog post in September 2023. Please share any feedback you have on this post on our Community Forum. Older versions of the roadmap May 2018 October 2018 Read more…

Developing Keyman

Keyman Update for 9 May 2025

This blog reports on significant Keyman product and keyboard development updates over the period from 14 April 2025 — 9 May 2025. As always, you can follow all of our development online at github.com/keymanapp/keyman, and Read more…