How to make an Auto Clicker with Java? -
so wanted make program holds down mouse button me.
so far i've got this: http://pastebin.com/utjwdhy7
what i'm wondering how can stop it. also, realise stopping button makes no sense wouldn't able click anyway. tips on how i've done far nice.
edit (adding code):
package main; import javax.swing.*; import javax.swing.border.lineborder; import java.awt.*; import java.awt.event.actionevent; import java.awt.event.actionlistener; import java.awt.event.inputevent; import java.beans.propertychangelistener; public class clickforever extends jframe implements actionlistener { public static boolean isclicking = false; public void actionperformed(actionevent e) {} public void createframe() { initcomponents(); } public void initcomponents() { jframe frame = new jframe("autoclicker"); jpanel panel = new jpanel(true); jbutton button = new jbutton("okay"); jlabel label = new jlabel(); frame.setvisible(true); frame.setsize(350, 67); frame.setresizable(false); frame.setdefaultcloseoperation(exit_on_close); frame.setlocationrelativeto(null); frame.getcontentpane().add(panel, borderlayout.center); frame.add(panel); button.addactionlistener(new action() { @override public object getvalue(string s) { return null; } @override public void putvalue(string s, object o) {} @override public void setenabled(boolean b) {} @override public boolean isenabled() { return false; } @override public void addpropertychangelistener(propertychangelistener propertychangelistener) {} @override public void removepropertychangelistener(propertychangelistener propertychangelistener) {} @override public void actionperformed(actionevent actionevent) { if(isclicking){isclicking = false; return;} if(!isclicking){isclicking = true; return;} } }); label.setfont(new font("times new roman", 1, 16)); label.settext("click 'okay' start."); label.setborder(borderfactory.createlineborder(color.black)); panel.add(label); panel.setborder(new lineborder(color.black)); panel.add(button); } public static void main(string[] args) throws java.awt.awtexception, java.lang.interruptedexception { clickforever clickforever = new clickforever(); robot rbt = new robot(); clickforever.createframe(); while(true){ if(isclicking) rbt.mousepress(inputevent.button1_mask); if(!isclicking) ; } } }
add key listener frame, , when key pressed, stop pressing. note not work if frame goes out of focus, in case have listen global key press, believe more difficult.
Comments
Post a Comment