演示如何为 unicode 模拟键盘的代码。谨防:
- 您必须激活目标应用程序,因为键盘事件排队到活动应用程序...
- 目标应用程序必须支持 Unicode
#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;
}