返回顶部

收藏

模拟键盘操作发送字符串

更多

模拟键盘操作发送字符串

[C/C++]代码

void SendKey(CString   str)
{
  DWORD   sc,shift;   
  unsigned   char   vkey;   
  char   a;   
    for   (int   i=0;i<str.GetLength();i++)   
  {   
  a=str.GetAt(i);   
  sc=OemKeyScan(a);   
  shift=sc>>16;   
    vkey=MapVirtualKey(sc&0xffff,1);   
    if   (shift)   
  keybd_event(VK_SHIFT,0,0,0);   
    keybd_event(vkey,0,0,0);   
  keybd_event(vkey,0,KEYEVENTF_KEYUP,0);   
  if   (shift)   
  keybd_event(VK_SHIFT,0,KEYEVENTF_KEYUP,0);   
  }
}
TCHAR szDir[MAX_PATH];
GetCurrentDirectory(MAX_PATH,szDir);
CString curDir;
CString eclipsePath;
CString tomcatPath;
curDir.Format("%s\\workspace",szDir); 
eclipsePath.Format("%s\\eclipse\\eclipse.exe",szDir); 
tomcatPath.Format("%s\\apache-tomcat-6.0.26",szDir); 
ShellExecute(NULL,"open",eclipsePath,NULL,NULL,SW_SHOW);
Sleep(8000);
SendKey(curDir);
Sleep(10000);
        keybd_event(VK_MENU,0,0,0);
        keybd_event(VK_MENU,0,KEYEVENTF_KEYUP,0);
        keybd_event('W',0,0,0);   
        keybd_event('W',0,KEYEVENTF_KEYUP,0);
        keybd_event(VK_UP,0,0,0);
        keybd_event(VK_UP,0,KEYEVENTF_KEYUP,0);
        keybd_event(VK_EXECUTE,0,0,0);
        keybd_event(VK_EXECUTE,0,KEYEVENTF_KEYUP,0);
Sleep(500);
        keybd_event(VK_TAB,0,0,0);
        keybd_event(VK_TAB,0,KEYEVENTF_KEYUP,0);
        keybd_event('T',0,0,0);   
        keybd_event('T',0,KEYEVENTF_KEYUP,0);
        keybd_event('T',0,0,0);   
        keybd_event('T',0,KEYEVENTF_KEYUP,0);
        keybd_event('T',0,0,0);   
        keybd_event('T',0,KEYEVENTF_KEYUP,0);
        keybd_event(VK_TAB,0,0,0);
        keybd_event(VK_TAB,0,KEYEVENTF_KEYUP,0);
        keybd_event(VK_TAB,0,0,0);
        keybd_event(VK_TAB,0,KEYEVENTF_KEYUP,0);
        keybd_event(VK_TAB,0,0,0);
        keybd_event(VK_TAB,0,KEYEVENTF_KEYUP,0);
        keybd_event(VK_UP,0,0,0);
        keybd_event(VK_UP,0,KEYEVENTF_KEYUP,0);
        keybd_event(VK_TAB,0,0,0);
        keybd_event(VK_TAB,0,KEYEVENTF_KEYUP,0);
SendKey(tomcatPath);
Sleep(1000);
        keybd_event(VK_EXECUTE,0,0,0);
        keybd_event(VK_EXECUTE,0,KEYEVENTF_KEYUP,0);

标签:c++

收藏

0人收藏

支持

0

反对

0