Java enables intelligent machine to operate computer automatically

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.