Search code examples
c#.netvisual-c++keykeypress

C# equivalent of WM_CHAR key press event?


In C++ apps with PeekMessage/TranslateMessage you can invoke WM_CHAR messages that tell you which character has been pressed based on the current IME. This saves you from converting the keycode to the char code, which can be challenging for non-English IME's.

Does a .NET Window have the equivalent to the WM_CHAR windows messaging event? Can I aquire it somehow? Obviously I can listen for key events and convert keycodes to char codes but it may not be as robust as windows doing it internally.


Solution

  • It seems you are looking for the KeyPress event, and the KeyChar property of the supplied KeyPressEventArgs instance.