Jump to content

Stop/Start Blocking User Input as Part of Script?


koboldNinja

Recommended Posts

I'm currently working on making an autoswitcher for osbot. Is there a way to allow user input to the client, then temporarily block input and allow the bot to complete an action in response to a key press or something? I've had the script working in autoHotKey for a while now, but it uses image recognition and something that can actually interact with the client like OsBot would be a lot better. 

If anyone has any idea how to implement something like this, please let me know. I would really appreciate it. Thanks. 

  • Like 1
Link to comment
Share on other sites

10 minutes ago, Khaleesi said:

I'm pretty sure you can check if the input is enabled or disabled, but don't think you can change it in a script.
What are you trying to do? you can always us emouselistener on the bot to see where the user clicks?

I believe there is an F-Key that enables/disables user input (I forget which one Alek set it to) so you could so something like

 

if(userInputIsDisabled){
  
  getKeyboard().pressKey(DESIGNATED_F_KEY);
  
}

Although im not sure if the F-Key for enabling user input is still avaliable (I want to say it was F9?)

Link to comment
Share on other sites

Ideally, the user would press a key, input would be disabled, the bot would preform a switch, then input would be re-enabled. I could just use mouselistener to send all of the clicks from the user to the client... But that seems like a crude solution, and I'm not sure how well it would work. Will mouselistener also record things like click and drag? Being able to move the camera with the scroll wheel button is something I'd like to keep working while the script is running. 

 

How I did this in ahk (is unfinished and doesn't allow user to set custom gear yet):

w:: ; switch to range gear
    BlockInput MouseMove
    
    send {esc}
    
    RandSleep(5,10)
    
    MouseGetPos, startX, startY

    ImageSearch, X, Y, 0, 0, A_ScreenWidth, A_ScreenHeight, C:\Users\name\Desktop\OSRS_Item_Images\avasAssembler.png

    Random, pos_x, X, X+10
    Random, pos_y, Y, Y+10
        If (ErrorLevel == 0) {
            MouseMove, %pos_x%, %pos_y%, 0
            Click
        }
    RandSleep(5,10)
    ImageSearch, X, Y, 0, 0, A_ScreenWidth, A_ScreenHeight, C:\Users\name\Desktop\OSRS_Item_Images\VoidRangeHelm.png

    Random, pos_x, X, X+10
    Random, pos_y, Y, Y+10

        If (ErrorLevel == 0) {
            MouseMove, %pos_x%, %pos_y%, 0
            Click
        }
    RandSleep(5,10)        
    ImageSearch, X, Y, 0, 0, A_ScreenWidth, A_ScreenHeight, C:\Users\name\Desktop\OSRS_Item_Images\toxicBlowpipe.png

    Random, pos_x, X, X+10
    Random, pos_y, Y, Y+10
        If (ErrorLevel == 0) {
            MouseMove, %pos_x%, %pos_y%, 0
            Click
        }
    RandSleep(5,10)
    ImageSearch, X, Y, 0, 0, A_ScreenWidth, A_ScreenHeight, C:\Users\name\Desktop\OSRS_Item_Images\necklaceOfAnguish.png

    Random, pos_x, X, X+10
    Random, pos_y, Y, Y+10
        If (ErrorLevel == 0) {
            MouseMove, %pos_x%, %pos_y%, 0
            Click
        }
    RandSleep(5,10)
    MouseMove, %startX%, %startY%, 0
    
    BlockInput MouseMoveOff
return

 

Edited by koboldNinja
Link to comment
Share on other sites

I doubt you can toggle user input from a script, because otherwise that would be a potential security flaw. Imagine your bot messing up, but for some reason you can't intervene at all.

You could perhaps open a near-completely transparent Window to cover the bot screen and hide it again once you've made the switch. It's perhaps a very hacky solution, not to mention inefficient too.

Your best bet is to ask Alek to allow scripts to toggle user input, but there'd be some caveat like only local scripts could do it, or that you'd need to specify a flag that enables it for that one bot client.

  • Like 1
Link to comment
Share on other sites

20 hours ago, koboldNinja said:

I'm currently working on making an autoswitcher for osbot. Is there a way to allow user input to the client, then temporarily block input and allow the bot to complete an action in response to a key press or something? I've had the script working in autoHotKey for a while now, but it uses image recognition and something that can actually interact with the client like OsBot would be a lot better. 

If anyone has any idea how to implement something like this, please let me know. I would really appreciate it. Thanks. 

Is there any way I can try the autoswitcher once it is done? or is there a way I can try the version with AHK? Seems like a very great and unique idea, would love to use this for the lulz and see if it is actually better than the human switching ^^.

Link to comment
Share on other sites

56 minutes ago, dailysmoker said:

Is there any way I can try the autoswitcher once it is done? or is there a way I can try the version with AHK? Seems like a very great and unique idea, would love to use this for the lulz and see if it is actually better than the human switching ^^.

Sure. The AHK version doesn't have a gui or anything, but it still works perfectly fine. PM me if you want the code and I can tell you how to set it up for specific gear/prayer/spellbook setups. 

It wouldn't be a complete script that could go on the SDN or anything, but perhaps I could just use osbot to read info from the client and then pass it to ahk? Again, it's a crude solution, but it does seem like a functional workaround. 

  • Like 1
Link to comment
Share on other sites

I've come up with a solution using an JWindow to overlay on top of the game screen. This blocks mouse clicks, and the overlay is black and transparent, so you can still see what you're doing and know when you're clicks are being blocked. Additionally, only the game screen is blocked and not the bot control bar, so you can stop the script (which dismisses the overlay entirely).

The overlay will reposition itself over the game screen when you hide/show it, not when you move the bot client around. Bare that in mind. You can add your own WindowListener to the bot canvas if you want, but I'm pretty sure the last thing you're doing when your swapping between your loadouts is moving the client about.

TestScript.java

import javax.swing.SwingUtilities;

import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

@ScriptManifest(author = "LiveRare", info = "", logo = "", name = "Block User Input", version = 0)
public class TestScript extends Script {
	
	WindowOverlay wo;
	
	@Override
	public void onStart() throws InterruptedException {
		
		SwingUtilities.invokeLater(() -> {
			
			/* Initialise the window overlay */
			wo = new WindowOverlay(bot.getCanvas());
		});
		
	}
	
	@Override
	public int onLoop() throws InterruptedException {
		
		/* Make sure the WindowOverlay exists before we use it */
		if (wo != null) {
			
			/* Check whether mouse clicks are blocked*/
			if (isRealMouseBlocked()) {
				
				/* TODO Switch gear */
				
				hideWindowOverlay();
				
			} else {
				
				/* TODO wait for request to fast-switch gear */
				
				showWindowOverlay();
			}
		}
		
		return 250;
	}
	
	@Override
	public void onExit() throws InterruptedException {
		
		/* VERY IMPORTANT - DISPOSE OF THE WINDOWOVERLAY!!! */
		SwingUtilities.invokeLater(() -> {
			if (wo != null) {
				wo.dispose();
			}
		});
	}

	
	private synchronized boolean isRealMouseBlocked() {
		return wo.isVisible();
	}
	
	private synchronized void showWindowOverlay() {
		wo.setVisible(true);
	}
	
	private synchronized void hideWindowOverlay() {
		wo.setVisible(false);
	}
}

 

WindowOverlay.java

import java.awt.Color;
import java.awt.Component;
import javax.swing.JWindow;

public class WindowOverlay extends JWindow {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private final Component component;
	
	public WindowOverlay(Component component) {
		super();
		super.setSize(component.getSize());
		super.setOpacity(0.314f);
		super.getContentPane().setBackground(Color.BLACK);
		
		this.component = component;
	}
	
	@Override
	public void setVisible(boolean b) {
		super.setVisible(b);
		if (b) {
			super.setLocation(component.getLocationOnScreen());
		}
	}
	
}

 

With this, you should be able to write an entire kit-switching script for OSBot without the need for any other third-party macros. Although, I would look into creating your own bot mouse, because the default one may be too slow.

Edited by liverare
  • 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.
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...