Jump to content
Elysiano

Need help with code optimization

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...