Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Try asking for help in the chatbox
  • pressKey/releaseKey/holdKey functions?


    holic
     Share

    Recommended Posts

    Hey all,

    I've been going through the javadocs tirelessly trying to find any sort of pressKey or holdKey type functions with no luck.

    I know not everything DreamBot is in the docs (like setDrawMouse) so I thought I'd ask about it.

    If there isn't a method with the current API, is there something along the lines of this that I could do instead?

    (new KeyboardEvent(getClient().getInstance(), "", false)).pressSpecialKey(KeyEvent.VK_CONTROL);

     

    I want to be able to hold control and click at the same time to sprint.

    Link to comment
    Share on other sites

    You may be able to use something similar to this, though I haven't been able to test it.

    Instance instance = getClient().getInstance();
    Canvas canvas = instance.getCanvas();
    Inventory inventory = getInventory();
    
    instance.setKeyboardInputEnabled(true);
    mouse.getMouseSettings();
    canvas.dispatchEvent(new KeyEvent(canvas, KeyEvent.KEY_PRESSED, System.currentTimeMillis(), 0, KeyEvent.VK_CONTROL, KeyEvent.CHAR_UNDEFINED));
    	//code
    canvas.dispatchEvent(new KeyEvent(canvas, KeyEvent.KEY_RELEASED, System.currentTimeMillis(), 0, KeyEvent.VK_CONTROL, KeyEvent.CHAR_UNDEFINED));
    instance.setKeyboardInputEnabled(false);

     

    Link to comment
    Share on other sites

    1 hour ago, StonedFarmer said:

    You may be able to use something similar to this, though I haven't been able to test it.

    Thanks StonedFarmer, that gives me a good starting point. I'll report back if I figure out a working method.

    Link to comment
    Share on other sites

    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
     Share

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.