Skip to content

Instantly share code, notes, and snippets.

@kalaspuffar
Created February 21, 2022 06:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kalaspuffar/6ff03f57755a16777febf16c402be2ec to your computer and use it in GitHub Desktop.
Save kalaspuffar/6ff03f57755a16777febf16c402be2ec to your computer and use it in GitHub Desktop.
Autoclicker code.
package org.ea;
import javax.swing.*;
import java.awt.*;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
public class AutoClicker implements KeyListener {
static boolean enabled = false;
public static void main(String[] args) {
AutoClicker ac = new AutoClicker();
try {
JFrame f=new JFrame();
f.addKeyListener(ac);
f.setSize(100, 100);
f.setVisible(true);
Robot r = new Robot();
int button = InputEvent.BUTTON1_DOWN_MASK;
while (true) {
if(enabled) {
System.out.println("Click");
r.mousePress(button);
Thread.sleep(400);
r.mouseRelease(button);
}
Thread.sleep( 2000);
}
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_A) {
enabled = !enabled;
}
}
@Override
public void keyReleased(KeyEvent e) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment