1 PackageCom.tz.util;2 3 ImportJava.awt.Robot;4 Importjava.awt.event.InputEvent;5 Importjava.awt.event.KeyEvent;6 7 /** 8 * @authorSunshine9 * @version1.0Ten * @date: August 16, 2015 PM 1:29:39 One * @description: Robot for Automation A * Overall function automatically click on the Computer Start button, click Run, - * Enter the cmd command into the DOS command window, view the current directory dir, - * View native IP information, exit exit the */ - Public classRobotcmd { - - Public Static voidMain (string[] args) { + Try { - //Instantiate a robot +Robot Robot =NewRobot (); A at //move to the Start menu position First -Robot.mousemove (24, 880); - - robot.mousepress (inputevent.button1_mask); - robot.mouserelease (inputevent.button1_mask); -Robot.delay (500); in - //move to the location of the Run menu, and click toRobot.mousemove (245, 666); + robot.mousepress (inputevent.button1_mask); - robot.mouserelease (inputevent.button1_mask); theRobot.delay (500); * $ //Robot Press the CMD keyPanax Notoginseng robot.keypress (keyevent.vk_c); - robot.keypress (keyevent.vk_m); the robot.keypress (keyevent.vk_d); +Robot.delay (500); A the //Click OK to enter the CMD console +Robot.mousemove (145, 745); - robot.mousepress (inputevent.button1_mask); $ robot.mouserelease (inputevent.button1_mask); $Robot.delay (500); - - //Enter the dir command the int[] Keydir ={keyevent.vk_d,keyevent.vk_i,keyevent.vk_r,keyevent.vk_enter}; -Keyutil.presskeys (robot, Keydir, 500);Wuyi the //Enter the ipconfig command - int[] Keyipconfig ={keyevent.vk_i,keyevent.vk_p,keyevent.vk_c,keyevent.vk_o,keyevent.vk_n,keyevent.vk_f,keyevent.vk_i, Keyevent.vk_g,keyevent.vk_enter}; WuKeyutil.presskeys (robot, Keyipconfig, 500); - About //Enter the exit command $ int[] Keyexit ={keyevent.vk_e,keyevent.vk_x,keyevent.vk_i,keyevent.vk_t,keyevent.vk_enter}; -Keyutil.presskeys (robot, Keyexit, 500); - - A +}Catch(Exception e) { the e.printstacktrace (); - } $ } the}
1 PackageCom.tz.util;2 3 ImportJava.awt.Robot;4 5 /** 6 * @authorSunshine7 * @version1.08 * @date: August 16, 2015 PM 2:05:239 * @description: Keyboard event Action Tool classTen */ One Public classKeyutil { A - /** - * Keyboard Input Method the * - * @paramrobot Robot class - * @paramkeys enter keyboard key name - * @paramDelay Time + * @returnvoid None - * + */ A Public Static voidPresskeys (Robot Robot,int[] keys,intdelay) { at - //Iterate through an array and assign a value - for(inti=0;i<keys.length;i++){ - robot.keypress (Keys[i]); - robot.keyrelease (Keys[i]); - Robot.delay (delay); in } - } to}
Java enables intelligent machine to operate computer automatically