From d4b5ac062d335d6424594cc12460bfce65c47be3 Mon Sep 17 00:00:00 2001 From: LenaGmbh Date: Tue, 16 Sep 2025 23:04:09 +0200 Subject: [PATCH] Added AutoClicker functionality --- src/main/java/AutoClicker.java | 54 ++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/main/java/AutoClicker.java diff --git a/src/main/java/AutoClicker.java b/src/main/java/AutoClicker.java new file mode 100644 index 0000000..f19115f --- /dev/null +++ b/src/main/java/AutoClicker.java @@ -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(); + } + } + } + } +}