Mouse camera with mouse ussing de java Robot

How can´t do this movement?.

I´m ussing java swing with jogl, (JFrame in wich are a JGLJPanel) and for each mouseMoved event, I create a Robot and call a function that do the camera movement and used the robot for put the mouse on the screen center.

But then other mouseMovedEvent happen (for the movement the mouse for the Robot) and the camera return to the fist position.

Some idea how will do that?

I read many Topics in the forum for this subject, but i´dont undestands how do this.

Not 100% sure how to do this, but the Jake2 project uses Robot in this way so you may be able to find some information by looking through the source code of that project.

Well, it’s simple. You have to set a flag for ignoring the Robot’s movement.

So, you set some flag, let the robot move the mouse… in your listener you check that flag… if its false you process the event as usual and otherwise you unset the flag.

But how can know if is a MouseEventListener movement for the mouse o for de Robot?.

Because coud be when the robot execute the movement, already exist another event mousemotion for the mouse waiting his turn. Then the next mousemotionlistener to execute when de robot move the mouse is not necesarily the event for the robot :frowning:

Thanks, i´m going to look this source code :wink:

But how can know if is a MouseEventListener movement for the mouse o for de Robot?

Its alternating. Starting with a non robot event.

User, robot, user, robot… just like that.

SwingUtilities.invokeLater(new Runnable()
{
   public void run()
   {
        set ignore-event flag
        robot.doSomething();
   }
});
SwingUtilities.invokeLater(new Runnable()
{
   public void run()
   {
        reset ignore-event flag
   }
});

interesting.
Riven, why the Swing.Utilities.invokeLater(…) ?

Imagine you click the mouse very fast, 2 times.

Without performing it on the EDT:


Input A
Input B
EDT: Event Input A (processed)
Do robot things -> Input C
ignore events with flag
EDT: Event Input B (ignored: wrong)
process events with flag (maybe here?)
EDT: Event Input C (processed or ignored: shaky)
Do robot things -> Input D ? (or not... if ignored)
process events with flag (maybe here?)

In short: it becomes very unreliable.

Without running it on the EDT:


Input A
Input B
EDT: Event Input A (processed)
EDT: add Input A to end of event-queue: ignore events with flag, then Do robot things -> Input C on EDT
EDT: add reset-ignore-flag to end of event-queue
EDT: add Input B to end of event-queue: ignore events with flag, then Do robot things -> Input D on EDT
EDT: add reset-ignore-flag to end of event-queue

< END of EDT event queue
    1. ignore, robot, new event C
           event C is processed here
    2. reset-ignore-flag

maybe something else here, doesn't matter

    3. ignore, robot, new event D
           event D is processed here
    4. reset-ignore-flag
>

Errrrr… sorry, this should be it:


SwingUtilities.invokeLater(new Runnable()
{
   public void run()
   {
        set ignore-event flag
        robot.doSomething();

         SwingUtilities.invokeLater(new Runnable()
         {
            public void run()
            {
                 reset ignore-event flag
            }
         });
   }
});