Emit input using WM_CHAR message?

I am working on a virtual keyboard for windows. I know that I can generate keyboard events using (for example) keybd_event() using a virtual key code, but this method is completely impractical and does not allow me to output (for example) Chinese or Russian characters or the least difficult.

Is it possible, in windows, to simulate a keyboard event by sending a WM_CHAR message? That would be ideal if I could do this because I would just need to extract the char code from the encoded UTF-8 or UTF-16 configuration file and send a message.

If possible, how can I do this in Windows CE and Windows Mobile? I need to support both desktop and mobile devices.

Thank you for your help!:)

+8
c ++ c windows events unicode
source share
1 answer

Code demonstrating how to simulate a Unicode keyboard. Caution:

  • you must activate the target application since keyboard events are queued for the active application ...
  • target application must be in unicode format
 #include <Windows.h> #include <tchar.h> static void send_unicode( wchar_t ch ) { INPUT input; // init input.type = INPUT_KEYBOARD; input.ki.time = 0; input.ki.dwExtraInfo = 0; input.ki.wVk = 0; input.ki.dwFlags = KEYEVENTF_UNICODE; input.ki.wScan = ch; // down SendInput( 1, &input, sizeof( INPUT ) ); // up input.ki.dwFlags |= KEYEVENTF_KEYUP; SendInput( 1, &input, sizeof( INPUT ) ); } int _tmain(int argc, _TCHAR* argv[]) { _tprintf( TEXT( "you have 5 seconds to switch to an application which accepts unicode input (as Word)...\n" ) ); Sleep( 5000); _tprintf( TEXT( "Sending...\n" ) ); send_unicode( 946 ); // lowercase greek beta send_unicode( 269 ); // lowercase c-hachek send_unicode( 12449 ); // japanese katakana small a send_unicode( 4595 ); // korean hangul jongseong phieuph-pieup return 0; } 
+2
source share

All Articles