Created
October 14, 2025 16:01
-
-
Save Joxebus/224ebaff97ec9bef32d09beee408af5a to your computer and use it in GitHub Desktop.
This script move the mouse automatically
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.awt.Robot; | |
| import java.awt.Toolkit; | |
| import java.awt.event.KeyEvent; | |
| import java.util.Date; | |
| public class MouseMover { | |
| private static final Robot robot; | |
| static { | |
| try { | |
| robot = new Robot(); | |
| } catch (Exception e) { | |
| throw new RuntimeException("Failed to initialize Robot", e); | |
| } | |
| } | |
| private static void moveMouseInSineWave() { | |
| int height = (int)(Toolkit.getDefaultToolkit().getScreenSize().getHeight() / 2) - 10; | |
| int width = (int)Toolkit.getDefaultToolkit().getScreenSize().getWidth(); | |
| double twoPI = Math.PI * 2.0; | |
| for (int x = 0; x < width; x += 2) { | |
| int y = (int)(height * Math.sin((twoPI * x) / width) + height); | |
| robot.mouseMove(x, y); | |
| try { | |
| Thread.sleep(4); | |
| } catch (InterruptedException e) { | |
| Thread.currentThread().interrupt(); | |
| break; | |
| } | |
| } | |
| } | |
| private static void changeTab(int times) { | |
| for (int i = 0; i < times; i++) { | |
| try { | |
| robot.keyPress(KeyEvent.VK_META); | |
| robot.keyPress(KeyEvent.VK_TAB); | |
| Thread.sleep(100); | |
| robot.keyRelease(KeyEvent.VK_TAB); | |
| } catch (InterruptedException e) { | |
| Thread.currentThread().interrupt(); | |
| break; | |
| } | |
| } | |
| robot.keyPress(KeyEvent.VK_ENTER); | |
| robot.keyRelease(KeyEvent.VK_ENTER); | |
| robot.keyRelease(KeyEvent.VK_META); | |
| } | |
| public static void main(String[] args) { | |
| System.out.println("Mouse mover will start in 15 seconds..."); | |
| try { | |
| Thread.sleep(5000); | |
| } catch (InterruptedException e) { | |
| Thread.currentThread().interrupt(); | |
| return; | |
| } | |
| System.out.println("Mouse mover started. Press Ctrl+C to stop."); | |
| while (true) { | |
| try { | |
| moveMouseInSineWave(); | |
| System.out.printf("Mouse wave completed at %s%n", new Date()); | |
| changeTab(3); | |
| Thread.sleep(60000); | |
| } catch (InterruptedException e) { | |
| System.out.println("Program interrupted"); | |
| break; | |
| } catch (Exception e) { | |
| System.out.printf("Error: %s%n", e.getMessage()); | |
| System.exit(1); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment