first working version
This commit is contained in:
63
src/main/java/de/lusiardi/mousemover/Main.java
Normal file
63
src/main/java/de/lusiardi/mousemover/Main.java
Normal file
@@ -0,0 +1,63 @@
|
||||
package de.lusiardi.mousemover;
|
||||
|
||||
import java.awt.AWTException;
|
||||
import java.awt.Robot;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
|
||||
public class Main {
|
||||
private static boolean running = false;
|
||||
private static Thread t = null;
|
||||
|
||||
public static void main(String[] args) throws AWTException,
|
||||
InterruptedException {
|
||||
JFrame main = new JFrame("ScreenSaverDisabler");
|
||||
final JButton startStop = new JButton("Start");
|
||||
startStop.addActionListener(new ActionListener() {
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (running) {
|
||||
running = false;
|
||||
startStop.setText("Start");
|
||||
} else {
|
||||
running = true;
|
||||
startStop.setText("Stop");
|
||||
Runnable r = new Runnable() {
|
||||
|
||||
public void run() {
|
||||
Robot r = null;
|
||||
try {
|
||||
r = new Robot();
|
||||
} catch (AWTException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
while (running == true) {
|
||||
r.keyPress(KeyEvent.VK_CONTROL);
|
||||
r.keyRelease(KeyEvent.VK_CONTROL);
|
||||
try {
|
||||
Thread.sleep(10000);
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
t = new Thread(r);
|
||||
t.start();
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
main.add(startStop);
|
||||
main.pack();
|
||||
main.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
main.setVisible(true);
|
||||
|
||||
}
|
||||
}
|
||||
BIN
src/main/resources/mm.ico
Normal file
BIN
src/main/resources/mm.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
Reference in New Issue
Block a user