zoukankan      html  css  js  c++  java
  • Java防锁屏小程序 IT

    为防止系统桌面自动锁屏,只需打成jar包,写个批处理程序start.bat,双击执行保持dos窗口执行即可,无其他影响。

    程序设计为每30秒动一次鼠标,可根据需要调整。

    附代码:

     1 package main;
     2 
     3 import java.awt.AWTException;
     4 import java.awt.Dimension;
     5 import java.awt.MouseInfo;
     6 import java.awt.Point;
     7 import java.awt.PointerInfo;
     8 import java.awt.Robot;
     9 import java.awt.Toolkit;
    10 
    11 public class Main {
    12     public static void main(String[] args) {
    13         Robot robot = null;
    14         try {
    15             robot = new Robot();
    16         } catch (AWTException e1) {
    17             e1.printStackTrace();
    18         }
    19         Point pos = MouseInfo.getPointerInfo().getLocation();
    20 
    21         int last_x = pos.x;
    22         int last_y = pos.y;
    23 
    24         int mov = 1;
    25 
    26         Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    27 
    28         System.out.println("Screen size: " + screenSize.getWidth() + "*" + screenSize.getHeight());
    29         while (true) {
    30             System.out.println(pos.x + " " + pos.y);
    31             PointerInfo pos_info = MouseInfo.getPointerInfo();
    32             if (pos_info == null) {
    33                 System.out.println("Get location fail!");
    34                 try {
    35                     Thread.sleep(30000L);
    36                 } catch (InterruptedException e) {
    37                     e.printStackTrace();
    38                 }
    39 
    40             } else {
    41                 pos = pos_info.getLocation();
    42 
    43                 if ((pos.x == last_x) && (pos.y == last_y)) {
    44                     System.out.println("moving!");
    45 
    46                     if (pos.y <= 0) {
    47                         mov = 1;
    48                     }
    49                     if (pos.y > 0) {
    50                         mov = -1;
    51                     }
    52                     robot.mouseMove(pos.x, pos.y + mov);
    53 
    54                     robot.mouseMove(pos.x, pos.y);
    55                 }
    56                 pos_info = MouseInfo.getPointerInfo();
    57                 if (pos_info == null) {
    58                     System.out.println("Get location fail!");
    59                     try {
    60                         Thread.sleep(30000L);
    61                     } catch (InterruptedException e) {
    62                         e.printStackTrace();
    63                     }
    64 
    65                 } else {
    66                     pos = pos_info.getLocation();
    67 
    68                     last_x = pos.x;
    69                     last_y = pos.y;
    70                     try {
    71                         Thread.sleep(30000L);
    72                     } catch (InterruptedException e) {
    73                         e.printStackTrace();
    74                     }
    75                 }
    76             }
    77         }
    78     }
    79 }
    View Code

    将这个Main类打成jar包,此处jar包名为MouseMove.jar;与jar包同目录位置写个.bat类型文件,文件内容如下:

    @echo off
    java -jar MouseMove.jar

    双击执行即可。

  • 相关阅读:
    已解决】Sublime中运行带input或raw_input的Python代码出错:EOFError: EOF when reading a line(转)
    暂时解决Sublime Text 2不支持input问题(转)
    Python中的注释(转)
    You don't have permission to access / on this server
    mysql开启慢查询方法(转)
    php获取当前url完整地址
    js中日期转换为时间戳
    发现js端日期跟php端日期格式不一致
    首发Zend Studio正式版注册破解(转)
    Arduino入门笔记(3):单LED闪烁
  • 原文地址:https://www.cnblogs.com/itfeng813/p/11579360.html
Copyright © 2011-2022 走看看