Hello, im wondering if anyone here could help me out, this is the first time i try to make a simple macro program
anyway this program i have set it to press a key and click the mouse, (This is for an MMO)
the question im having is, How do i make the program switch to the game when i want the key to be pressed ? i want to do other things on my computer while the macro is clicking on the same key in this game, currently when i activate the macro, i have to switch to the game and let it do its thing, but i want the program to automatically, when its suppose to press the key it does it inside the game and not on something i have open.
here is my code
Code:
import java.awt.*;
import java.awt.event.*;
import java.awt.AWTException;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import net.miginfocom.swing.MigLayout;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class TERA extends JFrame {
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
TERA frame = new TERA();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public TERA() throws AWTException {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(new MigLayout("", "[]", "[][]"));
final Robot myRobot = new Robot();
JButton btnMouse = new JButton("Mouse");
btnMouse.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
myRobot.delay(2000);
for (int i = 0; i < 5; i++) {
//myRobot.mouseMove(1005, i);
myRobot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
myRobot.delay(1000);
myRobot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
}
}
});
contentPane.add(btnMouse, "cell 0 0");
JButton keyButton = new JButton("Key");
keyButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
myRobot.delay(5000);
for (int i = 0; i < 10; i++) {
myRobot.keyPress(KeyEvent.VK_F);
myRobot.delay(15000);
}
}
});
contentPane.add(keyButton, "cell 0 1");
}
}
i read some posts here, saying C++ is a better program to deal with online gaming and such, im not the best programmer out there but i am alright, so if C++ is the better choice, i could switch
but my question would still be the same as above, how do i make the program do its thing inside the game and not on something i have open ( like internet, word or something like that )
Thanks