现在的位置: 首页 > 综合 > 正文

向系统发送英文汉字混合消息的函数void SendKeys(char * str)

2012年04月26日 ⁄ 综合 ⁄ 共 558字 ⁄ 字号 评论关闭
#define KEYEVENTF_UNICODE 0x4
void SendKeys(char *str)
{
 INPUT Input;
 WCHAR unicodeWord[512];
 memset(unicodeWord,0,sizeof(unicodeWord));
 MultiByteToWideChar(CP_THREAD_ACP,MB_COMPOSITE,str,strlen(str),unicodeWord,512);;
 
 for(  int i=0 ; unicodeWord[i]!=0 ; i++ )
 {
  Input.type =INPUT_KEYBOARD;
  Input.ki.wVk =0;
  Input.ki.wScan =unicodeWord[i];
  Input.ki.dwFlags = KEYEVENTF_UNICODE;
  Input.ki.time = 1000;
  Input.ki.dwExtraInfo = GetMessageExtraInfo();
  SendInput( 1, &Input , sizeof(INPUT) );
  Input.ki.dwFlags = KEYEVENTF_UNICODE | KEYEVENTF_KEYUP;
  SendInput( 1, &Input , sizeof(INPUT) );
 }
}
 

抱歉!评论已关闭.