Java Robot 类模拟键盘按键和鼠标点击(全局模拟)(2)

//输入syso并用alt+/快捷键补全
  robot.keyPress(KeyEvent.VK_S);
  robot.keyRelease(KeyEvent.VK_S);
  robot.delay(200);
  robot.keyPress(KeyEvent.VK_Y);
  robot.keyRelease(KeyEvent.VK_Y);
  robot.delay(200);
  robot.keyPress(KeyEvent.VK_S);
  robot.keyRelease(KeyEvent.VK_S);
  robot.delay(200);
  robot.keyPress(KeyEvent.VK_O);
  robot.keyRelease(KeyEvent.VK_O);
  robot.delay(200);
  robot.keyPress(KeyEvent.VK_ALT);
  robot.keyPress(KeyEvent.VK_SLASH);
  robot.keyRelease(KeyEvent.VK_ALT);
  robot.keyRelease(KeyEvent.VK_SLASH);
  robot.delay(500);

//输入双引号
  robot.keyPress(KeyEvent.VK_SHIFT);
  robot.keyPress(KeyEvent.VK_QUOTE);
  robot.keyRelease(KeyEvent.VK_SHIFT);
  robot.keyRelease(KeyEvent.VK_QUOTE);

//输入HelloWorld
  robot.keyPress(KeyEvent.VK_CAPS_LOCK);
  robot.keyRelease(KeyEvent.VK_CAPS_LOCK);
  robot.delay(500);
  robot.keyPress(KeyEvent.VK_H);
  robot.keyRelease(KeyEvent.VK_H);
  robot.delay(200);
  robot.keyPress(KeyEvent.VK_CAPS_LOCK);
  robot.keyRelease(KeyEvent.VK_CAPS_LOCK);
  robot.delay(200);
  robot.keyPress(KeyEvent.VK_E);
  robot.keyRelease(KeyEvent.VK_E);
  robot.delay(200);
  robot.keyPress(KeyEvent.VK_L);
  robot.keyRelease(KeyEvent.VK_L);
  robot.delay(200);
  robot.keyPress(KeyEvent.VK_L);
  robot.keyRelease(KeyEvent.VK_L);
  robot.delay(200);
  robot.keyPress(KeyEvent.VK_O);
  robot.keyRelease(KeyEvent.VK_O);
  robot.delay(200);
  robot.keyPress(KeyEvent.VK_CAPS_LOCK);
  robot.keyRelease(KeyEvent.VK_CAPS_LOCK);
  robot.delay(200);
  robot.keyPress(KeyEvent.VK_W);
  robot.keyRelease(KeyEvent.VK_W);
  robot.delay(200);
  robot.keyPress(KeyEvent.VK_CAPS_LOCK);
  robot.keyRelease(KeyEvent.VK_CAPS_LOCK);
  robot.delay(200);
  robot.keyPress(KeyEvent.VK_O);
  robot.keyRelease(KeyEvent.VK_O);
  robot.delay(200);
  robot.keyPress(KeyEvent.VK_R);
  robot.keyRelease(KeyEvent.VK_R);
  robot.delay(200);
  robot.keyPress(KeyEvent.VK_L);
  robot.keyRelease(KeyEvent.VK_L);
  robot.delay(200);
  robot.keyPress(KeyEvent.VK_D);
  robot.keyRelease(KeyEvent.VK_D);
  robot.delay(200);

//ctrl+shift+F 格式化
  robot.keyPress(KeyEvent.VK_SHIFT);
  robot.keyPress(KeyEvent.VK_CONTROL);
  robot.keyPress(KeyEvent.VK_F);
  robot.keyRelease(KeyEvent.VK_SHIFT);
  robot.keyRelease(KeyEvent.VK_CONTROL);
  robot.keyRelease(KeyEvent.VK_F);
 
  //ctrl+S保存
  robot.keyPress(KeyEvent.VK_CONTROL);
  robot.keyPress(KeyEvent.VK_S);
  robot.keyRelease(KeyEvent.VK_S);
  robot.keyRelease(KeyEvent.VK_CONTROL);
 
  //F11运行
  robot.keyPress(KeyEvent.VK_F11);
  robot.keyRelease(KeyEvent.VK_F11); 
 
 } 
}

代码可以从这里下载

------------------------------------------分割线------------------------------------------

免费下载地址在

用户名与密码都是

具体下载目录在 /2015年资料/7月/15日/Java Robot 类模拟键盘按键和鼠标点击(全局模拟)/

下载方法见

------------------------------------------分割线------------------------------------------

代码不一定在所有的电脑上都运行成功,大���可以根据自己的实际情况适当修改代码。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/b4faea8bff6ed977f4d02ae0a4068bf3.html