Compare commits
2 Commits
285e51f8c4
...
f1ea71ce52
| Author | SHA1 | Date | |
|---|---|---|---|
| f1ea71ce52 | |||
|
|
d4b5ac062d |
54
src/main/java/AutoClicker.java
Normal file
54
src/main/java/AutoClicker.java
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
import com.github.kwhat.jnativehook.GlobalScreen;
|
||||||
|
import com.github.kwhat.jnativehook.NativeHookException;
|
||||||
|
import com.github.kwhat.jnativehook.keyboard.NativeKeyEvent;
|
||||||
|
import com.github.kwhat.jnativehook.keyboard.NativeKeyListener;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.InputEvent;
|
||||||
|
|
||||||
|
public class AutoClicker implements NativeKeyListener {
|
||||||
|
private static boolean hotKeyPressed = false;
|
||||||
|
private static Thread clickThread;
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
try {
|
||||||
|
GlobalScreen.registerNativeHook();
|
||||||
|
GlobalScreen.addNativeKeyListener(new AutoClicker());
|
||||||
|
Clicker();
|
||||||
|
} catch (NativeHookException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Clicker() {
|
||||||
|
int mask = InputEvent.BUTTON1_DOWN_MASK;
|
||||||
|
clickThread = new Thread(() -> {
|
||||||
|
try {
|
||||||
|
Robot bot = new Robot();
|
||||||
|
while (hotKeyPressed) {
|
||||||
|
bot.mousePress(mask);
|
||||||
|
bot.mouseRelease(mask);
|
||||||
|
Thread.sleep(10);
|
||||||
|
}
|
||||||
|
} catch (AWTException | InterruptedException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
clickThread.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void nativeKeyPressed(NativeKeyEvent e) {
|
||||||
|
if(e.getKeyCode() == NativeKeyEvent.VC_F6) {
|
||||||
|
hotKeyPressed = !hotKeyPressed;
|
||||||
|
System.out.println("Autoclicker: " + hotKeyPressed);
|
||||||
|
if(!hotKeyPressed && clickThread != null) {
|
||||||
|
clickThread.interrupt();
|
||||||
|
try {
|
||||||
|
clickThread.join();
|
||||||
|
} catch (InterruptedException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user