Jump to content

[Snippet] ConcurrentMouseAPI; schedule mouse tasks to run one after the other


Recommended Posts

Posted (edited)

Source: https://github.com/Bobrocket/ConcurrentMouseAPI

 

ConcurrentMouseAPI allows you to move the mouse in a different way to the default OSBot API.

How?

 

The MouseScheduler class will spawn a new thread, which, when mouse targets are scheduled, will simply execute them one after the other in order of their priority. IMMEDIATE tasks run first, and LOWEST tasks run, well, last.

 

Example usage:

scheduler.schedule(new RectangleMouseTarget(new Rectangle(200, 200, 20, 20), MousePriority.NORMAL, MouseTarget.MOUSE_NO_CLICK)); //Despite being scheduled first, this will be ran second (after the IMMEDIATE task)
scheduler.schedule(new RectangleMouseTarget(new Rectangle(500, 500, 20, 20), MousePriority.LOWEST, MouseTarget.MOUSE_NO_CLICK)); //Despite being scheduled second, this will be ran last
scheduler.schedule(new NPCMouseTarget("Banker tutor", MousePriority.IMMEDIATE, MouseTarget.MOUSE_NO_CLICK)); //Despite being scheduled last, this will be ran first

You can also check the Main.java class in the github link (REMEMBER TO REMOVE IT BEFORE WRITING CODE)

 

This is incredibly useful for stuff like prayer flicking, 3 tick fishing, and inventory management. In the case of prayer flicking, you might have a separate thread to move the mouse every ~500ms. This might clash with your main logic, for example your NPC attacking or potion drinking.

Using ConcurrentMouseAPI, you can simply create prayer flicking as an IMMEDIATE task, therefore it's executed first. Clean prayer flicking with little code and no clashing!

 

NOTE: Methods which use the default mouse API (such as NPC#interact()) will not use ConcurrentMouseAPI and thus may affect the performance of it. If you want to correctly and properly utilise ConcurrentMouseAPI, convert all of your #interacts to MouseTargets and you're good to go.

Edited by Bobrocket
  • Like 6
  • 4 weeks later...
  • 2 weeks later...
Posted
    private void loop() {
        while (true) {
            try {
                IMouseTarget currentTarget = targetQueue.poll();
                if (currentTarget != null) {
                    while (!currentTarget.run(context)) Thread.sleep(50);
                }
                Thread.sleep(20);
            }
            catch (Exception ex) { }
        }
    }

nice infinite loop my friend

 

 

 

schedulingThread = new Thread(() -> loop());

ok

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...