• 鼠标不停的移动


     
    import java.awt.AWTException; 
    import java.awt.Dimension; 
    import java.awt.Robot; 
    import java.awt.Toolkit; 
    import java.awt.event.InputEvent; 
    import java.util.Random;
    
    /**
     * 鼠标不停的移动
     *
     */
    public class MouseController implements Runnable {
        private Dimension dim;  
        private Random rand;  
        private Robot robot;   
        private volatile boolean stop = false;  
        
        public MouseController() {   
               dim = Toolkit.getDefaultToolkit().getScreenSize();   
               rand = new Random();  
               try {   
                    robot = new Robot();   
               } catch (AWTException ex) {  
                   ex.printStackTrace();  
               }
               
        }
        
        public void run() {  
               while(!stop) {   
                    int x = rand.nextInt(dim.width);  
                    int y = rand.nextInt(dim.height);  
                    robot.mouseMove(x, y);   
                    robot.mousePress(InputEvent.BUTTON1_MASK);  
                     try {
                        Thread.sleep(10);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }   
                     
               }
        }
        
        public synchronized void stop() {  
               stop = true;  
        }   
        
        public static void main(String[] args) {  
    
            MouseController mc = new MouseController();  
    
            Thread mcThread = new Thread(mc);  
            System.out.println("Mouse Controller start");  
            mcThread.start();  
    
            try {  
                Thread.sleep(30000);  
            } catch (InterruptedException ex) {  
                ex.printStackTrace();  
            }  
            mc.stop();  
            System.out.println("Mouse Controller stoped");  
    
        } 
        
    }
  • 相关阅读:
    C primer plus 摘抄(第三章 数据和C)
    lambda表达式+python内置函数
    补充(pass)
    If语句和while语句
    解释器和编译器的区别
    关于python编码
    初识Python
    unity学习(一)ide窗口
    unity学习
    redis实践 —— redisReply简析
  • 原文地址:https://www.cnblogs.com/fuyuanming/p/4953531.html
Copyright © 2020-2023  润新知