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.

有帮助吗?

解决方案

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 ) ) ;
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top