简体   繁体   中英

How to convert a message from a WH_KEYBOARD_LL to corespondig unicode char

hello I'm writing a multilingual app and I'm using a WH_KEYBOARD_LL hook. I doesn't mater why I'm using the hook, I'm tried multiple things but this is the simplest and fastest way to do it. Now inside the hook proc

LRESULT CALLBACK LowLevelKeyboardProc(int nCode,WPARAM wParam, LPARAM lParam);

I receive a KBDLLHOOKSTRUCT in LPARAM parameter which contains the info for the pressed key. Is there any way to concert this info in an unicode character according to the current keyboard layout that the user has set so for ex. if the user has a Chinese keyboard layout set and he preses the "a" key then I receive a KBDLLHOOKSTRUCT containing the "a" key scan code and I need to convert this scan code to the corresponding unicode character. I know this is possible because you can write in Chinese in Microsoft Word, I just can't figure out how to do it.

Thanks.

ToUnicodeEx(). It doesn't work in practice unless the keyboard layout is simple. The dead keys is what kills you. Michael Kaplan wrote an 11 part blog serial about it but afaict he just gave up without finishing it. See what you can salvage from it but don't get your hopes up. Chinese use an IME, an Input Method Editor. Software, I think it builds up the character by strokes.

May be something like MapVirtualKeyEx or ToUnicodeEx. Anyway, I think a function from the Keyboard Input section of MSDN will contain a proper function (the list of them is short).

That conversion is complicated. Even simple deadkeys are annoying to handle, and when using an IME gets very ugly.

Consider intercepting the messages where the input control receives the already converted character. But of course that's much uglier to code.

The problem is that a normal message hook requires dll injection into the target process, and that dll should not be written in C#. But perhaps there is some other message interception API that works without dll injection.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM