4

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.

bala
  • 275
  • 2
  • 3
  • 13
  • I think you're looking in the wrong place - the raw keyboard input is not the place where much of this language specific stuff is done. Maybe you need to look at simulating IME and/or some of the Acessibility APIs. – Roger Rowland Dec 19 '13 at 05:49
  • As I am a chinese, I should say that the Chinese keyboard layout is same with en-us. The input of Chinese glyphs is performed using input methods. – jiandingzhe Dec 19 '13 at 06:57
  • @jiandingzhe Can you elaborately explain me, How do i use SendInput method for Chinese character? – bala Dec 19 '13 at 08:24
  • @user2778665 I know very little on windows API, and I don't know if SendInput can work with characters wider than 8 bit. If not, you need an "input methods", which is a program that intercepts your key stroke, parse them in specific ways (most commonly, as sound punctuation), list several candidate characters in a window, and then you select the wanted characters. – jiandingzhe Dec 19 '13 at 12:35

1 Answers1

2

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 ) ) ;
manuell
  • 7,528
  • 5
  • 31
  • 58