Adblock breaks this site

(Java) Sending text + newline to Runescape

Discussion in 'Programming General' started by Blupig, Mar 8, 2017.

Thread Status:
Not open for further replies.
  1. Blupig

    Blupig BEEF TOILET
    $5 USD Donor

    Joined:
    Nov 23, 2006
    Posts:
    7,145
    Referrals:
    16
    Sythe Gold:
    1,609
    Discord Unique ID:
    178533992981594112
    Valentine's Singing Competition Winner Member of the Month Winner MushyMuncher Gohan has AIDS Extreme Homosex World War 3 I'm LAAAAAAAME
    Off Topic Participant
    (Java) Sending text + newline to Runescape

    I'm writing an autotalker. It works great in general purpose applications like Notepad and even Old School Runescape, but it doesn't work in modern Runescape for some weird reason.

    If you select the option to add a new line at the end of your message, modern RS will move the chat window to the search window (as if it had pressed enter first before sending a message):
    [​IMG]

    Then it'll search for the autotalker's output.

    The character sequence is as simple as this: "hello\n" as an example. I've tried combinations with \r as well.

    My code is simple, I'm not doing anything crazy. Just using the Robot class.
    Here's my code:
    Code:
    package botkitfx.Classes;
    
    import java.awt.*;
    import java.awt.event.*;
    import java.util.Random;
    
    public class KeyController
    {
        Robot robot;
     
        public KeyController() throws AWTException
        {
            robot = new Robot();
        }
     
        public void SendChar(char c)
        {
            int keycode = KeyEvent.getExtendedKeyCodeForChar(c);
            robot.keyPress(keycode);
        }
     
        public void SendKeys(String text, int humanDelay, int humanOffset, boolean newline)
        {
            char[] textArr = text.toCharArray();
    
            for(char c : textArr)
            {
                int trueDelay;
                if (humanOffset > 0 && humanDelay > 0)
                    trueDelay = humanDelay + (new Random()).nextInt(humanOffset);
                else if(humanOffset == 0 && humanDelay > 0)
                    trueDelay = humanDelay;
                else
                    trueDelay = 0;
             
                SendChar(c);
            }
         
            if (newline == true)
            {
                SendChar('\n');
            }
        }
    }
    
    
    Usage:
    Code:
    SendKeys("hello", 0, 0, true);
    Sending VK_ENTER with Robot yields the same effect.

    Ideas?

    EDIT:
    Basic SendKeys.Send() code in C# doesn't invoke the search box, but it glitches out pretty heavily:
    [​IMG]
    This was trying to send "Boogers\n"
     
    Last edited: Mar 8, 2017
    Ex likes this.
  2. kmjt

    kmjt -.- The nocturnal life chose me -.-
    Banned

    Joined:
    Aug 21, 2009
    Posts:
    14,450
    Referrals:
    8
    Sythe Gold:
    449
    (Java) Sending text + newline to Runescape

    I don't play runescape anymore so I'm not familiar with the interface. I worked with Robot a few years ago (also Java) and if I can recall correctly, adding some delay between key sends fixed a lot of the weird behavior I was getting compared with no delay. Perhaps the game is having trouble interpreting your new line because it is coming in so fast? In runescape, is typing \n supposed to start a new line?
     
  3. Blupig

    Blupig BEEF TOILET
    $5 USD Donor

    Joined:
    Nov 23, 2006
    Posts:
    7,145
    Referrals:
    16
    Sythe Gold:
    1,609
    Discord Unique ID:
    178533992981594112
    Valentine's Singing Competition Winner Member of the Month Winner MushyMuncher Gohan has AIDS Extreme Homosex World War 3 I'm LAAAAAAAME
    Off Topic Participant
    (Java) Sending text + newline to Runescape

    Robot works with literal key presses so it uses keycodes instead of chars. Translating the char \n to a keycode is the equivalent of telling Robot to type "enter", so it should work fine. I haven't tried adding a delay though, I'll report back soon.

    EDIT: Added a simple Thread.sleep(50); and it works as intended now. Thx pal <3
     
    Last edited: Mar 8, 2017
    kmjt likes this.
  4. Mootrucks

    Mootrucks Hero
    Mootrucks Donor Retired Sectional Moderator Legendary

    Joined:
    May 16, 2015
    Posts:
    6,958
    Referrals:
    38
    Sythe Gold:
    30
    Discord Unique ID:
    247992974141554708
    Discord Username:
    mootrucks mobile#8797
    In Memory of Jon Homosex (4) Embar League of Legends Tournament Winner <3 n4n0 (5) Extreme Homosex (7)
    Poképedia St. Patrick's Day 2013 St. Patrick's Day 2014 St. Patrick's Day 2017 St. Patrick's Day 2018 Gohan has AIDS (7) I saw Matthew Former OMM
    (Java) Sending text + newline to Runescape

    Requested lock.
     
< MULTI SCREEN PROGRAMING | Formal education in programming >
Thread Status:
Not open for further replies.


 
 
Adblock breaks this site