Home > Blockchain >  Win32 - How to convert a Japanese character's virtual/scan code back to the character?
Win32 - How to convert a Japanese character's virtual/scan code back to the character?

Time:06-14

I have the virtual key and scan code for a particular character (in this case 'つ') and I would like to convert it back to the Japanese character. How should I go about doing it? I've searched and tried the below code. However, it's not working... It only works for if the characters are ASCII.

FYI.

  1. I am only saving the VK/SC and not generating a keypress directly so I can't work with WM_CHAR.
  2. The 'Z' key on a Japanese keyboard generates 'つ'

Here are the references: enter image description here

CodePudding user response:

IME is involved in this case. ToUnicode is working with usual keyboard layouts (that have SC/VK/CHAR tables inside their dlls).

AFAIK in Japanese case English keyboard layout is used with Japanese IME on top of it - thats why you cannot simply use ToUnicode to produce Japansese chars.

On the other side - IME injects WM_CHAR messages into your window's message queue after 'TranslateMessage' call. IMEs can be a quite complex. They can produce characters from different sources - keydown, voice, char etc.

Proper way is to process WM_CHAR and do not try to do deal with IME APIs by yourself...

  • Related