Jump to content

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


Bobrocket

Recommended Posts

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

  • 4 weeks later...
  • 2 weeks later...
    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

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.
Note: Your post will require moderator approval before it will be visible.

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