0

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.

Community
  • 1
  • 1
Robin Rodricks
  • 110,798
  • 141
  • 398
  • 607
  • 1
    Don't really understand this. The GUI components that can receive focus have KeyDown, KeyPress, KeyUp events? – Martin James Mar 29 '13 at 08:54
  • Yes, but `WM_CHAR` is different from `WM_KEYDOWN` in that it provides the unicode char code instead of the typical keycode. I was looking for that information in .NET. – Robin Rodricks Mar 29 '13 at 09:16

2 Answers2

3

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

Frédéric Hamidi
  • 258,201
  • 41
  • 486
  • 479
1

The closest approach to the MFC one is to use WndProc:

protected override void WndProc(ref Message m)
{

    if (m.Msg == WM_CHAR) //define WM_CHAR properly 
    {

    }
    base.WndProc(ref m);
}
Felice Pollano
  • 32,832
  • 9
  • 75
  • 115