Jump to content

Typing (faster) using the Keyboard class


Recommended Posts

Posted

Hey guys.

 

I have been writing a script and one the the remaining issues is that typing is very slow. I was wondering if there was a way to increase the speed, or better yet make the text instant (like a macro would).

 

Any comments would be appreciated. I am currently using the typeString method.

private Keyboard kb;
kb = getKeyboard();
kb.typeString(autoTalker.getMessage(), true);

Cheers.

Posted

Thanks for the suggestions guys. I implemented SmartKeyboard but it was still a bit slow for my liking (although very good stuff in there). I ended up using some of the code to come up with my own solution. The text isn't instant but typing can be interrupted and will resume where it left off.

 

Appreciate the help.

  • Like 1
Posted

Thanks for the suggestions guys. I implemented SmartKeyboard but it was still a bit slow for my liking (although very good stuff in there). I ended up using some of the code to come up with my own solution. The text isn't instant but typing can be interrupted and will resume where it left off.

 

Appreciate the help.

 

If you post your additions in the SmartKeyboard thread I'd be glad to go through and implement them :)

Posted

I don't think SmartKeyboard would benefit much from what I have done.. I'll just post my class here in case you wanted to scrounge anything (or if anyone has the same problem I did). You'll see I stole your pressEnter method tongue.png

 

The point of AutoTalker is to spam a message, but I also needed to accept trade offers. Originally the script had to wait until it had finished typing before accepting the trade - which was a problem because it sometimes took >5 seconds to respond to people and they would lose interest.

 

I used no loops so you can effectively type and do other tasks at the same time (such as trading other players in my case). And even if you go into a state where you aren't typing anything (trading screen), you can resume exactly where you left off.

import java.util.ArrayList;
import org.osbot.rs07.api.Keyboard;

public class AutoTalker {
	
	private ArrayList<Character> messageArrayList;
	private char[] messageArray;
	public int messageIndex;	
	
	private Keyboard keyboard;
	
	public AutoTalker(Keyboard kb) {		
		messageIndex = 0;
		keyboard = kb;
	}
	
	public void talk() {
		if (keyboard.typeKey(messageArrayList.get(messageIndex))) {
			if (messageIndex == messageArrayList.size() -1) {
				pressEnter();
			}
			messageIndex = (messageIndex + 1) % messageArrayList.size();
		}
	}
	
	public void setMessage(String newMessage) {
		messageArrayList = new ArrayList<Character>();
		messageArray = newMessage.toCharArray();
		for (char ch : messageArray) {
			messageArrayList.add(ch);
		}
	}
	
	public boolean pressEnter() {
		keyboard.typeKey((char)13);
		keyboard.typeKey((char)10);
		return true;
	}
}

Its not much but I'm proud of it, gets the job done smile.png

  • Like 1

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