您好,登錄后才能下訂單哦!
為防止系統(tǒng)桌面自動鎖屏,只需打成jar包,寫個批處理程序start.bat,雙擊執(zhí)行保持dos窗口執(zhí)行即可,無其他影響。
程序設(shè)計為每30秒動一次鼠標(biāo),可根據(jù)需要調(diào)整。
附代碼:
package main; import java.awt.AWTException; import java.awt.Dimension; import java.awt.MouseInfo; import java.awt.Point; import java.awt.PointerInfo; import java.awt.Robot; import java.awt.Toolkit; public class Main { public static void main(String[] args) { Robot robot = null; try { robot = new Robot(); } catch (AWTException e1) { e1.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) { 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(); } } } } } }
將這個Main類打成jar包,此處jar包名為MouseMove.jar;與jar包同目錄位置寫個.bat類型文件,文件內(nèi)容如下:
@echo off java -jar MouseMove.jar
雙擊執(zhí)行即可。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持億速云。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。