Compare commits

..

2 Commits

Author SHA1 Message Date
f1ea71ce52 Merge pull request 'Added AutoClicker functionality' (#1) from master into main 2025-09-16 23:04:53 +02:00
LenaGmbh
d4b5ac062d Added AutoClicker functionality 2025-09-16 23:04:09 +02:00

View 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();
}
}
}
}
}