资源预览内容
第1页 / 共3页
第2页 / 共3页
第3页 / 共3页
亲,该文档总共3页全部预览完了,如果喜欢就下载吧!
资源描述
/ 可以在 eclipse下直接运行的示例程序:package key_robot; import java.awt.*; import java.awt.event.*; import javax.swing.JOptionPane; publicclass key_robot public key_robot() / 鼠标单击 , 要双击就连续调用privatestaticvoid pressMouse(Robot r, int m, int delay) r.mousePress(m); r.delay(10); r.mouseRelease(m); r.delay(delay); / 键盘输入方法privatestaticvoid pressKeys(Robot r, int ks, int delay) for ( int i = 0; i ks.length; i+) r.keyPress(ksi); r.delay(10); r.keyRelease(ksi); r.delay(delay); publicstaticvoid main(String args) throws Exception final Robot rb = new Robot(); new Thread() publicvoid run() rb.delay(2000); / 模拟回车rb.keyPress(KeyEvent.VK_ENTER ); rb.keyRelease(KeyEvent.VK_ENTER ); .start(); JOptionPane.showMessageDialog( null, “ 以下程序自动执行, 包括本对话框, 点击运行后请不要移动鼠标和键盘.n如果不能正常执行程序, 请先关闭输入法“ ); rb.delay(1500); / 设置开始菜单的大概位置int x = 40; inty = Toolkit.getDefaultToolkit().getScreenSize().height- 10; / 鼠标移动到开始菜单,rb.mouseMove(x, y); rb.delay(500); / 单击三次开始菜单for ( int i = 0; i 3; i+) pressMouse(rb, InputEvent.BUTTON1_MASK , 500); rb.delay(1000); / 运行 CMD 命令 r cmd enterint ks = KeyEvent.VK_R, KeyEvent.VK_C, KeyEvent.VK_M, KeyEvent.VK_D, KeyEvent.VK_ENTER , ; pressKeys(rb, ks, 500); rb.mouseMove(400, 400); rb.delay(500); / 运行 DIR 命令 dir enterks = newint KeyEvent.VK_D, KeyEvent.VK_I , KeyEvent.VK_R, KeyEvent.VK_ENTER ; pressKeys(rb, ks, 500); rb.delay(1000); / 运行 CLS命令 cls enterks = newint KeyEvent.VK_C, KeyEvent.VK_L , KeyEvent.VK_S, KeyEvent.VK_ENTER ; pressKeys(rb, ks, 500); rb.delay(1000); / 运行 EXIT 命令 exit enterks = newint KeyEvent.VK_E , KeyEvent.VK_X, KeyEvent.VK_I , KeyEvent.VK_T , KeyEvent.VK_ENTER ; pressKeys(rb, ks, 500); rb.delay(1000); / 右键测试x = Toolkit.getDefaultToolkit().getScreenSize().width - 10; rb.mouseMove(x, y); / 如果是双键鼠标, 请改用 InputEvent.BUTTON2_MASK标pressMouse(rb, InputEvent.BUTTON3_MASK , 500); / 显示日期调整对话框apressKeys(rb, newint KeyEvent.VK_A , 1000); rb.delay(2000); pressKeys(rb, newint KeyEvent.VK_ESCAPE , 0); rb.delay(1000); new Thread() publicvoid run() rb.delay(1000); / 回车rb.keyPress(KeyEvent.VK_ENTER ); rb.keyRelease(KeyEvent.VK_ENTER ); .start(); JOptionPane.showMessageDialog( null, “ 演示完毕 !“ );
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号