Jump to content

Need help with code optimization


Recommended Posts

Posted

Hello everyone,

 

I have been working on a mouse recorder which can be used inside OSBot.

 

It works fine, it repeats what I recorded, but it is ‘lagging’ when the mouse needs to move a lot of distance or just needs to move very fast circles (see .gifs below).

https://imgur.com/a/jfuEd5w - When I recorded the mouse movement (+/- 8 seconds)

https://imgur.com/a/B1mUOqf - When I played the recording of the mouse movement  (+/- 15 seconds)

 

As you can see, when the recording gets played it takes almost double the time.

 

This is the core of the code from the mouse player which plays the data from following .txt file (see attachments, too many lines for forum I think)

    //Plays the mouse data
    /*
    The mouseRecordingData is an arrayList which contains data from the txt file as where to move, etc.
     */
    void playMouseData() throws InterruptedException{
        for(int i = 0; i < mouseRecordingData.size(); i++){
            //move mouse
            getMouse().move(mouseRecordingData.get(i).getX(), mouseRecordingData.get(i).getY());

            sleep(mouseRecordingData.get(i).getTime());
        }
    }

 

I am wondering, what can I do to improve the smoothness and speed of the mouse recording to stop this ‘lagging’?

 

If you need more files or data, please let me know.

 

Thank you in advance!

MacroFile.txt

Posted
18 hours ago, Elysiano said:

Hello everyone,

 

I have been working on a mouse recorder which can be used inside OSBot.

 

It works fine, it repeats what I recorded, but it is ‘lagging’ when the mouse needs to move a lot of distance or just needs to move very fast circles (see .gifs below).

https://imgur.com/a/jfuEd5w - When I recorded the mouse movement (+/- 8 seconds)

https://imgur.com/a/B1mUOqf - When I played the recording of the mouse movement  (+/- 15 seconds)

 

As you can see, when the recording gets played it takes almost double the time.

 

This is the core of the code from the mouse player which plays the data from following .txt file (see attachments, too many lines for forum I think)


    //Plays the mouse data
    /*
    The mouseRecordingData is an arrayList which contains data from the txt file as where to move, etc.
     */
    void playMouseData() throws InterruptedException{
        for(int i = 0; i < mouseRecordingData.size(); i++){
            //move mouse
            getMouse().move(mouseRecordingData.get(i).getX(), mouseRecordingData.get(i).getY());

            sleep(mouseRecordingData.get(i).getTime());
        }
    }

 

I am wondering, what can I do to improve the smoothness and speed of the mouse recording to stop this ‘lagging’?

 

If you need more files or data, please let me know.

 

Thank you in advance!

MacroFile.txt

From my understanding, the getMouse().move(x,y) creates it's own path to the destination, So you trying to record each pixel movement, then calling getMouse().move(x, y), uses a lot of CPU. You'd be better off using a custom mouse controller ( to get perfect pixel to pixel recreation), or just recording where the mouse stops, and allow the OSBot mouse controller to create the path to it.

Posted
48 minutes ago, Slut said:

From my understanding, the getMouse().move(x,y) creates it's own path to the destination, So you trying to record each pixel movement, then calling getMouse().move(x, y), uses a lot of CPU. You'd be better off using a custom mouse controller ( to get perfect pixel to pixel recreation), or just recording where the mouse stops, and allow the OSBot mouse controller to create the path to it.

With custom mouse controller, do you mean the Java Robot Class and such?

As for the CPU usage, running the script and mouse recording does not seem to increase the CPU usage

Posted
17 hours ago, Elysiano said:

With custom mouse controller, do you mean the Java Robot Class and such?

 As for the CPU usage, running the script and mouse recording does not seem to increase the CPU usage

Well you can't use the Robot class through OSBot, the permissions are blocked for security reasons, but you can implement something similar, yes.

Posted
7 minutes ago, Elysiano said:

Yup really unfortunate. Do you have any similar custom mouse controllers you can recommend?

You can use the generateBotMouseEvent function to move the mouse instantly to another point:
 

public void moveMouseInstantly(final int x, final int y) {
    getBot().getMouseEventHandler().generateBotMouseEvent(MouseEvent.MOUSE_MOVED, System.currentTimeMillis(), 0, x, y, 0, false, MouseEvent.NOBUTTON, true);
}

 

  • Like 2
Posted
1 hour ago, Explv said:

You can use the generateBotMouseEvent function to move the mouse instantly to another point:
 


public void moveMouseInstantly(final int x, final int y) {
    getBot().getMouseEventHandler().generateBotMouseEvent(MouseEvent.MOUSE_MOVED, System.currentTimeMillis(), 0, x, y, 0, false, MouseEvent.NOBUTTON, true);
}

 

Thanks! It's running alot faster and more 'human like' now :) 

  • Like 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...