Jump to content

Typing (faster) using the Keyboard class


Tonare

Recommended Posts

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.

Link to comment
Share on other sites

As I wrote this class, I would recommend it. I do believe, however, that the default OSBot keyboard class is slow itself (which SmartKeyboard uses) - I'll see what I can do about speed later on, however I have other priorities as of late.

Link to comment
Share on other sites

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

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 :)

Link to comment
Share on other sites

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