private void typeStringInstant(String output){
for(int i = 0; i < output.length(); i ++){
char c = output.charAt(i);
int code = KeyEvent.getExtendedKeyCodeForChar(c);
// Type the character
getBot().getKeyEventHandler().generateBotKeyEvent(400, System.currentTimeMillis(), 0, code, c);
}
// Press enter
getBot().getKeyEventHandler().generateBotKeyEvent(401, System.currentTimeMillis(), 0, 10, '\u0000', 1);
// Release enter
getBot().getKeyEventHandler().generateBotKeyEvent(402, System.currentTimeMillis(), 0, 10, '\u0000', 1);
}
This works almost fine for me. You have to change one thing with the Press enter and release enter. I bet the method generateBotKeyEvent was updated because it shouldn't have the 1 at the end.
Instead it should be getBot().getKeyEventHandler().generateBotKeyEvent(401, System.currentTimeMillis(), 0, 10, '\u0000');
and getBot().getKeyEventHandler().generateBotKeyEvent(402, System.currentTimeMillis(), 0, 10, '\u0000');
Of course there is also some natural delay between when the chat is sent and when it appears, but it instantly types and sends the message.
The code I tested this with and worked is here:
package net.chatbox.instantchat;
import java.awt.event.KeyEvent;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
@ScriptManifest(author = "Helper", info = "Instant Chat", logo = "", name = "Instant Chatter", version = 0)
public class InstantChat extends Script{
@Override
public int onLoop() throws InterruptedException {
return 100;
}
public void onStart(){
typeStringInstant("This probably will work just fine for me");
}
public void onExit() {
typeStringInstant("Double-checking this");
}
private void typeStringInstant(String output)
{
for(int i = 0; i < output.length(); i++)
{
char c = output.charAt(i);
int code = KeyEvent.getExtendedKeyCodeForChar(c);
// Type the character
getBot().getKeyEventHandler().generateBotKeyEvent(400, System.currentTimeMillis(), 0, code, c);
}
// Press enter
getBot().getKeyEventHandler().generateBotKeyEvent(401, System.currentTimeMillis(), 0, 10, '\u0000');
// Release enter
getBot().getKeyEventHandler().generateBotKeyEvent(402, System.currentTimeMillis(), 0, 10, '\u0000');
}
}