摸鱼神器(保持Teams一直处于绿色状态)

package org.cloud.sonic.controller.tools;

import java.awt.*;
import java.time.DayOfWeek;
import java.time.LocalDateTime;
import java.time.LocalTime;

/**
 * @author Philip Lee
 * @date 2024/1/9 16:10
 */
public class Test {
    public static void main(String[] args) {
        Robot robot = null;
        try {
            robot = new Robot();
        } catch (AWTException e) {
            e.printStackTrace();
        }

        Point pos = MouseInfo.getPointerInfo().getLocation();

        int last_x = pos.x;
        int last_y = pos.y;

        int mov = 1;

        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

        System.out.println("Screen size: " + screenSize.getWidth() + " * " + screenSize.getHeight());

        while (true) {

            LocalDateTime currentTime = LocalDateTime.now();

            // 获取当前是星期几
            DayOfWeek currentDay = currentTime.getDayOfWeek();

            // 获取当前时间的时分
            LocalTime currentTimeOnly = currentTime.toLocalTime();

            // 检查是否在工作时间范围内 在每个星期一到星期五早晨9:00-12:00、下午13:30-18:00 这期间算满足条件
            boolean isWorkingHours = (currentDay != DayOfWeek.SATURDAY && currentDay != DayOfWeek.SUNDAY) &&
                    ((currentTimeOnly.isAfter(LocalTime.of(9, 0)) && currentTimeOnly.isBefore(LocalTime.of(12, 0))) ||
                            (currentTimeOnly.isAfter(LocalTime.of(13, 30)) && currentTimeOnly.isBefore(LocalTime.of(18, 0))));

            if (isWorkingHours) {
                System.out.println("当前时间在工作时间范围内");
                // 在这里执行你的代码逻辑
                System.out.println(pos.x + " " + pos.y);
                PointerInfo pos_info = MouseInfo.getPointerInfo();
                if (pos_info == null) {
                    System.out.println("get location fail!");
                    try {
                        Thread.sleep(30000L);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                } else {
                    pos = pos_info.getLocation();
                    if (pos.x == last_x && pos.y == last_y) {
                        System.out.println("Moving!");
                        if (pos.y <= 0) {
                            mov = 1;
                        }
                        if (pos.y > 0) {
                            mov = -1;
                        }
                        robot.mouseMove(pos.x, pos.y + mov);
                        robot.mouseMove(pos.x, pos.y);
                    }
                    pos_info = MouseInfo.getPointerInfo();
                    if (pos_info == null) {
                        System.out.println("Get location fail!");
                        try {
                            Thread.sleep(30000L);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    } else {
                        pos = pos_info.getLocation();
                        last_x = pos.x;
                        last_y = pos.y;
                        try {
                            Thread.sleep(30000L);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            } else {
                System.out.println("当前时间不在工作时间范围内");
            }


        }
    }
}

  • 9
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值