koboldNinja Posted February 19, 2018 Share Posted February 19, 2018 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. 1 Quote Link to comment Share on other sites More sharing options...
Khaleesi Posted February 19, 2018 Share Posted February 19, 2018 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? Quote Link to comment Share on other sites More sharing options...
Muffins Posted February 19, 2018 Share Posted February 19, 2018 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?) Quote Link to comment Share on other sites More sharing options...
koboldNinja Posted February 19, 2018 Author Share Posted February 19, 2018 (edited) 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 February 19, 2018 by koboldNinja Quote Link to comment Share on other sites More sharing options...
liverare Posted February 20, 2018 Share Posted February 20, 2018 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. 1 Quote Link to comment Share on other sites More sharing options...
Alek Posted February 20, 2018 Share Posted February 20, 2018 You cannot override any settings set by the botter in the client. The only exception is BreakManager, in which the botter is prompted with a message informing him/her about the override. Quote Link to comment Share on other sites More sharing options...
dailysmoker Posted February 20, 2018 Share Posted February 20, 2018 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 ^^. Quote Link to comment Share on other sites More sharing options...
koboldNinja Posted February 20, 2018 Author Share Posted February 20, 2018 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. 1 Quote Link to comment Share on other sites More sharing options...
liverare Posted February 20, 2018 Share Posted February 20, 2018 (edited) 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 February 20, 2018 by liverare 1 Quote Link to comment Share on other sites More sharing options...
koboldNinja Posted February 20, 2018 Author Share Posted February 20, 2018 Awesome, thanks liverare! I can't promise that I'll be successful, but I'll try to have something working finished in a week or two. More than happy to share it with everyone once I'm done. Quote Link to comment Share on other sites More sharing options...