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("当前时间不在工作时间范围内");
}
}
}
}
摸鱼神器(保持Teams一直处于绿色状态)
最新推荐文章于 2024-05-31 10:46:10 发布