Any pointers on how accented characters are implemented in Windows would be helpful.
Goal – Ability to add accented characters(áéíóú) using keystrokes like ctrl + ‘ followed by a vowel and all other combinations that work on standard applications like MS Word, Text pad etc.
My Findings till date –
Everywhere I could read documentation/blogs/forums related to WM_DEADCHAR message.What I understand is :
::TranslateMessage translates WM_KEYUP messages corresponding to dead keys into WM_DEADCHAR messages, and it translates WM_SYSKEYUP messages generated by dead keys into WM_SYSDEADCHAR messages. Windows provides the logic that combines these messages with character messages to produce accented characters, so dead-key messages are usually passed on for default processing.
I added this message to my CWnd derived class’s message map but OnDeadChar() never gets called. Additionally I have found out using SPY++ that even in MSWord,Textpad etc where accented characters could be added with combination of these keystrokes, WM_DEADCHAR message is never dispatched.
So, Does this mean that WM_DEADCHAR is actually not the way to address this issue?
Please provide any sample code/steps/mechanism to implement accented characters.
Thanks in advance!!!
This is all dependent on the keyboard layout you are using. Certain keyboard layouts have dead keys which basically allow for key combinations for producing more characters.
For example my ` key does nothing by itself, but pressing ` then a produces
à.In terms of allowing users to input accented characters, it’s really up to them to install a keyboard layout which allows for it. Your app does not need to handle
WM_DEADCHAR; you can just handleWM_CHAR.In terms of supporting accented characters internally in your app, just make sure you’re using the Unicode character set and types. For example
wchar_t/WCHAR, and notchar.For what it’s worth, I believe I had the same goal as you at some point. I created an app that basically simulates dead keys and would produce accented characters using keyboard hooks. The advantage is that you get the accented char functionality without installing a keyboard layout.
The disadvantages are more numerous though. There’s no point re-invent this wheel. Keyboard layouts are surprisingly powerful, and all these issues with inputting characters have been solved already. You will have a very hard time translating your own messages to generate different characters. Different apps have different requirements in this regard, and in the end you will need to completely simulate keystrokes, to the point of generating keyboard state structures and handling every keyboard / char / input message. So as you are developing this, you’ll notice that it works fine for Notepad, but doesn’t work for Winword. Then you fix for winword, and then discover that it doesn’t work for Qt apps. I would definitely suggest using keyboard layouts.
But maybe this is not what you’re trying to do; in that case ignore what I said 😀