How can I create something like a second mouse that can control my application without taking over the real mouse?
If you are wondering what I am doing - I am trying to make something like a bot.
Printable View
How can I create something like a second mouse that can control my application without taking over the real mouse?
If you are wondering what I am doing - I am trying to make something like a bot.
Why would you want to do that? This smells like a design flaw.
It seems to me you would need to replicate the signal your operating system sends to programs when the mouse does things. Without some specialized tools, that is going to be very hard.
So... How can I do this?
If you're trying to mess with non Java windows, use C++ or some other language being closer to the OS.
Java is the wrong choice for such tasks.
Did you have a look at java.awt.Robot ?
You could create your own mouse events and post them to the event queue.
Then you should ask the authors of the bots you have seen, how they did it, instead of asking here without providing any information what you're trying to do. Bye.
How would passing objects around between components move the mouse?Quote:
This is going to move the real mouse.
What it would do is fool the listening components into thinking that a mouse event had occurred.
Not with Java!
I don't get the concept of what you are trying to do?
Sounds like you want to have two cursors, one the moved by a program and one by the user.
What is "a mouse"? In a program its the receipt of mouse events. There is no "visual" image of a cursor moving over a screen for a program.Quote:
Nooo I need it to be a mouse
Can you explain this. What is the "it"? A cursor?Quote:
so it can go around the site and get xp
What is the "xp"?
There should be one cursor (the normal cursor) and there should be an invisible cursor for the program and if the program is minimised the invisible cursor will still do things in the program.
Yes, There should be no "visual" image of a cursor moving over a screen for a program.
It = invisible cursor
xp = the experience for the game.
How would you implement an "invisible cursor" for a program?
You create mouse events and pass them to the program. The program doesn't know where the mouse events came from and would assume that the "mouse" sent them.
Do some research on the MouseEvent class.
You create an instance of the class the same as with any other class.
Use new and give the constructor some args.
The trick is to put the mouse event object into the EventQueue for the app.
Here's some code I wrote for AWT several years ago to allow the pressing of the Enter key to be handled like a mouse click on a button, ie it passes an ActionEvent to the button. Don't know if it works with Swing.
Code:// MakeEnterDoAction.java
// Class to turn key press into an ActionEvent for a component
// A new instance of this class should be added as a KeyListener to the component
// that is to receive the ActionEvent: button.addKeyListener(new MakeEnterDoAction());
package NormsTools;
import java.awt.event.*;
import java.awt.*;
public class MakeEnterDoAction extends KeyAdapter {
public void keyPressed(KeyEvent ke) {
if (ke.getKeyCode() == KeyEvent.VK_ENTER) {
Object src = ke.getSource();
Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(
new ActionEvent(src,
ActionEvent.ACTION_PERFORMED,
"Enter"));
}
} // end keyPressed()
} // end class