java 定时启动window程序、自动滑动鼠标

马上要放10.1假期了,结果公司通知5-8号加班,需要远程办公,本人项目模块已经编写完成,预计加班任务很少,为了更好的远程办(划)公(水),特地写了这个脚本。

脚本介绍:

程序启动后,会一直执行,每天的8:50自动打开企业微信,之后每间隔10秒移动一次鼠标(企业微信中,如果长时间不进行操作会有挂机提示),这样就可以防止电脑睡眠,并且企业微信不会有挂机提示,有了这个程序,然后(✪ω✪)。。。。。

下面是完整代码:

public class HappyOnHook {
          
   

    private static int x = 0;
    private static int y = 0;

    public static void main(String[] args) {
          
   

        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.HOUR_OF_DAY, 8);
        calendar.set(Calendar.MINUTE, 50);
        calendar.set(Calendar.SECOND, 0);

        Date time = calendar.getTime();

        Timer timer = new Timer();
        timer.scheduleAtFixedRate(new TimerTask() {
          
   
            @SneakyThrows
            public void run() {
          
   
                Runtime.getRuntime().exec("D:\app\qywx\WXWork\WXWork.exe");
                start();
            }
        }, time, 1000 * 60 * 60 * 24);// 这里设定将延时每天固定执行
    }

    public static void start(){
          
   
        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
          
   
            @Override
            public void run() {
          
   
                change();
            }
        }, 1000,10000);
    }

    // 鼠标移动
    public static void change() {
          
   
        Robot robot;
        try {
          
   
            robot = new Robot();
//            robot.mouseMove(x,y);
            robot.mouseMove(x, y);
            //防止鼠标移动到屏幕死角
            x = x + 200;
            y = y + 100;
            if (x >= 2000) {
          
   
                x = 0;
            }
            if (y >= 1000) {
          
   
                y = 0;
            }
        } catch (AWTException e) {
          
   
            e.printStackTrace();
        }
    }
}

下面是升级版(仅适用于springboot):

懒人创造世界。。。奥利给!

经验分享 程序员 微信小程序 职场和发展