Reputation: 275
I have US standard keyboard but I would like to simulate the italian or chinese type of keystrokes by using SendInput method.
I use SendInput metode like this,
KEYBDINPUT kb = { 0 } ;
ZeroMemory ( & kb , sizeof ( KEYBDINPUT ) ) ;
ZeroMemory ( & kInput , sizeof ( INPUT ) ) ;
kb.wVk = 0 ;
kb.dwFlags = KEYEVENTF_UNICODE ;
kb.wScan = vk ; //vk is result of MapVirtualKey key API
kInput.type = INPUT_KEYBOARD ;
kInput.ki = kb ;
UINT res = SendInput ( 1 , & kInput , sizeof ( INPUT ) ) ;
Note :- Without change the keyboard settings.
Upvotes: 4
Views: 863
Reputation: 7620
When using KEYEVENTF_UNICODE
, the kb.wScan just has to be the wchar_t
unicode character.
Don't use MapVirtualKey
.
Also, don't forget to send the "Key Up" transition, just after the Key Down.
UINT res = SendInput ( 1 , & kInput , sizeof ( INPUT ) ) ;
kb.dwFlags |= KEYEVENTF_KEYUP;
res = SendInput ( 1 , & kInput , sizeof ( INPUT ) ) ;
Upvotes: 2