返回顶部

收藏

模拟键盘操作发送字符串

更多

模拟键盘操作发送字符串

[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

»更多 您可能感兴趣的代码
  1. 2017-07-23 12:42:20奇数魔方阵 by Kevin.
  2. 2017-07-18 14:15:24两种方法计算“算术表达式” by aiheng1988
  3. 2015-09-09 16:29:06将jpg转换为bmp格式的文件 by qqmmcc
  4. 2015-09-09 09:29:49可执行文件加密 by walker30
  5. 2015-09-08 18:42:46TCP端口占用查询 by 灵剑子
  6. 2015-09-08 14:16:34Luffar schack五子棋 by 蟋蟀哥
  7. 2015-09-08 10:39:34wav转mp3的程序 by 灵剑子
  8. 2015-09-05 16:54:59逐行搜索目录中的文件内容并输出到Excel by 蟋蟀哥
  9. 2015-09-03 20:10:15LZW+AES+Base64编码解码剪贴板文本 by 童学芬
  10. 2015-09-01 17:47:21猫里奥 by aiheng1988
  11. 2017-11-24 14:22:26使用scrapy抓取BLAH全部EPUB格至书籍 by 风云轩

发表评论