Compare commits
2 Commits
285e51f8c4
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
01ce57cd6e | ||
|
|
d4b5ac062d |
57
src/main/java/AutoClicker.java
Normal file
57
src/main/java/AutoClicker.java
Normal file
@@ -0,0 +1,57 @@
|
||||
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());
|
||||
} 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 ex) {
|
||||
ex.printStackTrace();
|
||||
} catch (InterruptedException ex) {
|
||||
// Thread got close
|
||||
}
|
||||
});
|
||||
clickThread.start();
|
||||
}
|
||||
|
||||
public void nativeKeyPressed(NativeKeyEvent e) {
|
||||
if(e.getKeyCode() == NativeKeyEvent.VC_F6) {
|
||||
hotKeyPressed = !hotKeyPressed;
|
||||
System.out.println("Autoclicker: " + hotKeyPressed);
|
||||
if(hotKeyPressed) {
|
||||
clicker();
|
||||
} else if(clickThread != null) {
|
||||
clickThread.interrupt();
|
||||
try {
|
||||
clickThread.join();
|
||||
} catch (InterruptedException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user