आप जावा के रोबोट वर्ग की मदद से इस का समाधान कर सकते हैं।
, स्क्रीनशॉट लेने के लिए रोबोट वर्ग का उपयोग करें तो देता है के लिए 60 सेकंड का कहना है कि और एक अन्य स्क्रीनशॉट लेने के लिए प्रतीक्षा करें। एक दूसरे के साथ स्क्रीनशॉट तुलना करें देखने के लिए कि किसी भी परिवर्तन हुआ है, लेकिन सिर्फ पिक्सेल द्वारा स्क्रीनशॉट पिक्सेल तुलना नहीं है। बदल गए पिक्सल के प्रतिशत की जांच करें। कारण यह है कि आपके पास Windows घड़ी की तरह छोटे मतभेद परिणाम के साथ हस्तक्षेप नहीं करना चाहती है। यदि प्रतिशत 0.005% (या जो भी हो) कम है, तो कंप्यूटर शायद निष्क्रिय है।
import java.awt.AWTException;
import java.awt.DisplayMode;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
public class CheckIdle extends Thread {
private Robot robot;
private double threshHold = 0.05;
private int activeTime;
private int idleTime;
private boolean idle;
private Rectangle screenDimenstions;
public CheckIdle(int activeTime, int idleTime) {
this.activeTime = activeTime;
this.idleTime = idleTime;
// Get the screen dimensions
// MultiMonitor support.
int screenWidth = 0;
int screenHeight = 0;
GraphicsEnvironment graphicsEnv = GraphicsEnvironment
.getLocalGraphicsEnvironment();
GraphicsDevice[] graphicsDevices = graphicsEnv.getScreenDevices();
for (GraphicsDevice screens : graphicsDevices) {
DisplayMode mode = screens.getDisplayMode();
screenWidth += mode.getWidth();
if (mode.getHeight() > screenHeight) {
screenHeight = mode.getHeight();
}
}
screenDimenstions = new Rectangle(0, 0, screenWidth, screenHeight);
// setup the robot.
robot = null;
try {
robot = new Robot();
} catch (AWTException e1) {
e1.printStackTrace();
}
idle = false;
}
public void run() {
while (true) {
BufferedImage screenShot = robot
.createScreenCapture(screenDimenstions);
try {
Thread.sleep(idle ? idleTime : activeTime);
} catch (InterruptedException e) {
e.printStackTrace();
}
BufferedImage screenShot2 = robot
.createScreenCapture(screenDimenstions);
if (compareScreens(screenShot, screenShot2) < threshHold) {
idle = true;
System.out.println("idle");
} else {
idle = false;
System.out.println("active");
}
}
}
private double compareScreens(BufferedImage screen1, BufferedImage screen2) {
int counter = 0;
boolean changed = false;
// Count the amount of change.
for (int i = 0; i < screen1.getWidth() && !changed; i++) {
for (int j = 0; j < screen1.getHeight(); j++) {
if (screen1.getRGB(i, j) != screen2.getRGB(i, j)) {
counter++;
}
}
}
return (double) counter
/(double) (screen1.getHeight() * screen1.getWidth()) * 100;
}
public static void main(String[] args) {
CheckIdle idleChecker = new CheckIdle(20000, 1000);
idleChecker.run();
}
}
ऐसा करने का कोई पोर्टेबल तरीका नहीं है। आप किस सिस्टम को लक्षित कर रहे हैं? निष्क्रिय होने की आपकी परिभाषा क्या है? –
शायद आपको इस संबंधित प्रश्न में समाधान मिल जाए: http://stackoverflow.com/questions/614227/how-to-detect-that-a-pc-has-been-idle-for-30-seconds-using-java – Prine