Jump to content

Typing a Random Key


Otterblast

Recommended Posts

Hello I have looked through a lot of different support stuff but can't seem to find a way to type a key

I looked up how to type a key into the game and am trying to randomly create a runescape name on tutorial island but having trouble

here is where I got the key references, I know this works as I have used code 32 for space before and it works just fine

https://stackoverflow.com/questions/15313469/java-keyboard-keycodes-list/31637206

here is my code so far

    public void randomKey() throws InterruptedException{
        int X = random(0,31);
        
        if(X == 1) {log("started key press");
            getKeyboard().pressKey(65);;
            sleep(random(100,200));
            getKeyboard().releaseKey(65);
        }else if(X == 2) {log("started key press");
            getKeyboard().pressKey(76);
            sleep(random(100,200));
            getKeyboard().releaseKey(76);
        }else if(X == 3) {log("started key press");
            getKeyboard().pressKey(73);
            sleep(random(100,200));
            getKeyboard().releaseKey(73);
        }else if(X == 4) {log("started key press");
            getKeyboard().pressKey(80);
            sleep(random(100,200));
            getKeyboard().releaseKey(80);
        }else if(X == 5) {log("started key press");
            getKeyboard().pressKey(82);
            sleep(random(100,200));
            getKeyboard().releaseKey(82);
        }else if(X == 6) {log("started key press");
            getKeyboard().pressKey(87);
            sleep(random(100,200));
            getKeyboard().releaseKey(87);
        }else if(X == 7) {log("started key press");
            getKeyboard().pressKey(77);
            sleep(random(100,200));
            getKeyboard().releaseKey(77);
        }else if(X == 😎 {log("started key press");
            getKeyboard().pressKey(85);
            sleep(random(100,200));
            getKeyboard().releaseKey(85);
        }else if(X == 9) {log("started key press");
            getKeyboard().pressKey(84);
            sleep(random(100,200));
            getKeyboard().releaseKey(84);
        }else if(X == 10) {log("started key press");
            getKeyboard().pressKey(79);
            sleep(random(100,200));
            getKeyboard().releaseKey(79);
        }else if(X == 11) {log("started key press");
            getKeyboard().pressKey(80);
            sleep(random(100,200));
            getKeyboard().releaseKey(80);
        }else if(X == 12) {log("started key press");
            getKeyboard().pressKey(89);
            sleep(random(100,200));
            getKeyboard().releaseKey(89);
        }else if(X == 13) {log("started key press");
            getKeyboard().pressKey(69);
            sleep(random(100,200));
            getKeyboard().releaseKey(69);
        }else if(X == 14) {log("started key press");
            getKeyboard().pressKey(83);
            sleep(random(100,200));
            getKeyboard().releaseKey(83);
        }else if(X == 15) {log("started key press");
            getKeyboard().pressKey(68);
            sleep(random(100,200));
            getKeyboard().releaseKey(68);
        }else if(X == 16) {log("started key press");
            getKeyboard().pressKey(70);
            sleep(random(100,200));
            getKeyboard().releaseKey(70);
        }else if(X == 17) {log("started key press");
            getKeyboard().pressKey(72);
            sleep(random(100,200));
            getKeyboard().releaseKey(72);
        }else if(X == 18) {log("started key press");
            getKeyboard().pressKey(71);
            sleep(random(100,200));
            getKeyboard().releaseKey(71);
        }else if(X == 19) {log("started key press");
            getKeyboard().pressKey(75);
            sleep(random(100,200));
            getKeyboard().releaseKey(75);
        }else if(X == 20) {log("started key press");
            getKeyboard().pressKey(88);
            sleep(random(100,200));
            getKeyboard().releaseKey(88);
        }else if(X == 21) {log("started key press");
            getKeyboard().pressKey(67);
            sleep(random(100,200));
            getKeyboard().releaseKey(67);
        }else if(X == 22) {log("started key press");
            getKeyboard().pressKey(86);
            sleep(random(100,200));
            getKeyboard().releaseKey(86);
        }else if(X == 23) {log("started key press");
            getKeyboard().pressKey(66);
            sleep(random(100,200));
            getKeyboard().releaseKey(66);
        }else if(X == 24) {log("started key press");
            getKeyboard().pressKey(78);
            sleep(random(100,200));
            getKeyboard().releaseKey(78);
        }else if(X == 25) {log("started key press");
            getKeyboard().pressKey(90);
            sleep(random(100,200));
            getKeyboard().releaseKey(90);
        }else if(X == 26) {log("started key press");
            getKeyboard().pressKey(48);
            sleep(random(100,200));
            getKeyboard().releaseKey(48);
        }else if(X == 27) {log("started key press");
            getKeyboard().pressKey(49);
            sleep(random(100,200));
            getKeyboard().releaseKey(49);
        }else if(X == 28) {log("started key press");
            getKeyboard().pressKey(50);
            sleep(random(100,200));
            getKeyboard().releaseKey(50);
        }else if(X == 29) {log("started key press");
            getKeyboard().pressKey(51);
            sleep(random(100,200));
            getKeyboard().releaseKey(51);
        }else if(X == 30) {log("started key press");
            getKeyboard().pressKey(52);
            sleep(random(100,200));
            getKeyboard().releaseKey(52);
        }else if(X == 31) {log("started key press");
            getKeyboard().pressKey(53);
            sleep(random(100,200));
            getKeyboard().releaseKey(53);
        }else if(X == 32) {log("started key press");
            getKeyboard().pressKey(54);
            sleep(random(100,200));
            getKeyboard().releaseKey(54);
        }else if(X == 33) {log("started key press");
            getKeyboard().pressKey(55);
            sleep(random(100,200));
            getKeyboard().releaseKey(55);
        }else if(X == 30) {log("started key press");
            getKeyboard().pressKey(56);
            sleep(random(100,200));
            getKeyboard().releaseKey(56);
        }else if(X == 30) {log("started key press");
            getKeyboard().pressKey(57);
            sleep(random(100,200));
            getKeyboard().releaseKey(57);
        }else {
            log("something wrong with X in randomKey");
            getKeyboard().pressKey(57);
            sleep(random(100,200));
            getKeyboard().releaseKey(57);
        }
        
    }

 

For reference I already have the bot interact with the namebar by clicking on it in a separate larger function that works fine, if I manually start typing it will go into the "please pick a unqiue display name" but for some reason typing won't?

Any help appreciated! 

Link to comment
Share on other sites

Just now, Otterblast said:

Hello I have looked through a lot of different support stuff but can't seem to find a way to type a key

I looked up how to type a key into the game and am trying to randomly create a runescape name on tutorial island but having trouble

here is where I got the key references, I know this works as I have used code 32 for space before and it works just fine

https://stackoverflow.com/questions/15313469/java-keyboard-keycodes-list/31637206

here is my code so far

    public void randomKey() throws InterruptedException{
        int X = random(0,31);
        
        if(X == 1) {log("started key press");
            getKeyboard().pressKey(65);;
            sleep(random(100,200));
            getKeyboard().releaseKey(65);
        }else if(X == 2) {log("started key press");
            getKeyboard().pressKey(76);
            sleep(random(100,200));
            getKeyboard().releaseKey(76);
        }else if(X == 3) {log("started key press");
            getKeyboard().pressKey(73);
            sleep(random(100,200));
            getKeyboard().releaseKey(73);
        }else if(X == 4) {log("started key press");
            getKeyboard().pressKey(80);
            sleep(random(100,200));
            getKeyboard().releaseKey(80);
        }else if(X == 5) {log("started key press");
            getKeyboard().pressKey(82);
            sleep(random(100,200));
            getKeyboard().releaseKey(82);
        }else if(X == 6) {log("started key press");
            getKeyboard().pressKey(87);
            sleep(random(100,200));
            getKeyboard().releaseKey(87);
        }else if(X == 7) {log("started key press");
            getKeyboard().pressKey(77);
            sleep(random(100,200));
            getKeyboard().releaseKey(77);
        }else if(X == 😎 {log("started key press");
            getKeyboard().pressKey(85);
            sleep(random(100,200));
            getKeyboard().releaseKey(85);
        }else if(X == 9) {log("started key press");
            getKeyboard().pressKey(84);
            sleep(random(100,200));
            getKeyboard().releaseKey(84);
        }else if(X == 10) {log("started key press");
            getKeyboard().pressKey(79);
            sleep(random(100,200));
            getKeyboard().releaseKey(79);
        }else if(X == 11) {log("started key press");
            getKeyboard().pressKey(80);
            sleep(random(100,200));
            getKeyboard().releaseKey(80);
        }else if(X == 12) {log("started key press");
            getKeyboard().pressKey(89);
            sleep(random(100,200));
            getKeyboard().releaseKey(89);
        }else if(X == 13) {log("started key press");
            getKeyboard().pressKey(69);
            sleep(random(100,200));
            getKeyboard().releaseKey(69);
        }else if(X == 14) {log("started key press");
            getKeyboard().pressKey(83);
            sleep(random(100,200));
            getKeyboard().releaseKey(83);
        }else if(X == 15) {log("started key press");
            getKeyboard().pressKey(68);
            sleep(random(100,200));
            getKeyboard().releaseKey(68);
        }else if(X == 16) {log("started key press");
            getKeyboard().pressKey(70);
            sleep(random(100,200));
            getKeyboard().releaseKey(70);
        }else if(X == 17) {log("started key press");
            getKeyboard().pressKey(72);
            sleep(random(100,200));
            getKeyboard().releaseKey(72);
        }else if(X == 18) {log("started key press");
            getKeyboard().pressKey(71);
            sleep(random(100,200));
            getKeyboard().releaseKey(71);
        }else if(X == 19) {log("started key press");
            getKeyboard().pressKey(75);
            sleep(random(100,200));
            getKeyboard().releaseKey(75);
        }else if(X == 20) {log("started key press");
            getKeyboard().pressKey(88);
            sleep(random(100,200));
            getKeyboard().releaseKey(88);
        }else if(X == 21) {log("started key press");
            getKeyboard().pressKey(67);
            sleep(random(100,200));
            getKeyboard().releaseKey(67);
        }else if(X == 22) {log("started key press");
            getKeyboard().pressKey(86);
            sleep(random(100,200));
            getKeyboard().releaseKey(86);
        }else if(X == 23) {log("started key press");
            getKeyboard().pressKey(66);
            sleep(random(100,200));
            getKeyboard().releaseKey(66);
        }else if(X == 24) {log("started key press");
            getKeyboard().pressKey(78);
            sleep(random(100,200));
            getKeyboard().releaseKey(78);
        }else if(X == 25) {log("started key press");
            getKeyboard().pressKey(90);
            sleep(random(100,200));
            getKeyboard().releaseKey(90);
        }else if(X == 26) {log("started key press");
            getKeyboard().pressKey(48);
            sleep(random(100,200));
            getKeyboard().releaseKey(48);
        }else if(X == 27) {log("started key press");
            getKeyboard().pressKey(49);
            sleep(random(100,200));
            getKeyboard().releaseKey(49);
        }else if(X == 28) {log("started key press");
            getKeyboard().pressKey(50);
            sleep(random(100,200));
            getKeyboard().releaseKey(50);
        }else if(X == 29) {log("started key press");
            getKeyboard().pressKey(51);
            sleep(random(100,200));
            getKeyboard().releaseKey(51);
        }else if(X == 30) {log("started key press");
            getKeyboard().pressKey(52);
            sleep(random(100,200));
            getKeyboard().releaseKey(52);
        }else if(X == 31) {log("started key press");
            getKeyboard().pressKey(53);
            sleep(random(100,200));
            getKeyboard().releaseKey(53);
        }else if(X == 32) {log("started key press");
            getKeyboard().pressKey(54);
            sleep(random(100,200));
            getKeyboard().releaseKey(54);
        }else if(X == 33) {log("started key press");
            getKeyboard().pressKey(55);
            sleep(random(100,200));
            getKeyboard().releaseKey(55);
        }else if(X == 30) {log("started key press");
            getKeyboard().pressKey(56);
            sleep(random(100,200));
            getKeyboard().releaseKey(56);
        }else if(X == 30) {log("started key press");
            getKeyboard().pressKey(57);
            sleep(random(100,200));
            getKeyboard().releaseKey(57);
        }else {
            log("something wrong with X in randomKey");
            getKeyboard().pressKey(57);
            sleep(random(100,200));
            getKeyboard().releaseKey(57);
        }
        
    }

 

For reference I already have the bot interact with the namebar by clicking on it in a separate larger function that works fine, if I manually start typing it will go into the "please pick a unqiue display name" but for some reason typing won't?

Any help appreciated! 

Holy shit dude that's some extremely overkill code.

Just do the following: 

(note indents are messed up for whatever reason.)

public void randomKey() throws InterruptedException{
		int random_length = random(n);
		// put the length you want your names to go up to as n
		for (int i = 0; i < random_length; i=i+1){
            		int X = random(48, 90);
        		getKeyboard.pressKey(x);
            		sleep(random(x,y);
        }
}

The following code will randomly generate a value from 0-9, a-z (Key codes 48 -> 90) and then loop for the max length you wish your name to be. In the loop it will type random characters that it generates. 

That should put you on the right lines. Don't believe you have to releaseKey() either when typing. I might be mistaken however and referring to another function.

 

Edited by Impensus
  • Like 1
Link to comment
Share on other sites

7 hours ago, Impensus said:

.

 

 I just tested it and It needs to be typeKey(char key).

I think this would be a little better becuase the range 48-90 has things that are non letters or numbers.

String AlphaNumericString = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                                    + "0123456789"
                                    + "abcdefghijklmnopqrstuvxyz"; 
  for (int i = 0; i < n; i++) { 
            int index 
                = (int)(AlphaNumericString.length() 
                        * Math.random()); 
      getKeyboard().typeKey(AlphaNumericString 
                          .charAt(index));
          sleep(random(x,y));

        } 

 

 

 

7 hours ago, Otterblast said:

Tip If you repeat the same exact code more then 3 times make it a funtion

 

Edited by Nbacon
  • Like 1
Link to comment
Share on other sites

11 hours ago, Nbacon said:

 

 I just tested it and It needs to be typeKey(char key).

I think this would be a little better becuase the range 48-90 has things that are non letters or numbers.


String AlphaNumericString = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                                    + "0123456789"
                                    + "abcdefghijklmnopqrstuvxyz"; 
  for (int i = 0; i < n; i++) { 
            int index 
                = (int)(AlphaNumericString.length() 
                        * Math.random()); 
      getKeyboard().typeKey(AlphaNumericString 
                          .charAt(index));
          sleep(random(x,y));

        } 

 

 

 

Tip If you repeat the same exact code more then 3 times make it a funtion

 

Ahh my bad I didn't check the keycode range, this solution is better so go with this :p.

Link to comment
Share on other sites

On 8/9/2020 at 12:32 PM, Impensus said:

Holy shit dude that's some extremely overkill code.

Just do the following: 

(note indents are messed up for whatever reason.)


public void randomKey() throws InterruptedException{
		int random_length = random(n);
		// put the length you want your names to go up to as n
		for (int i = 0; i < random_length; i=i+1){
            		int X = random(48, 90);
        		getKeyboard.pressKey(x);
            		sleep(random(x,y);
        }
}

The following code will randomly generate a value from 0-9, a-z (Key codes 48 -> 90) and then loop for the max length you wish your name to be. In the loop it will type random characters that it generates. 

That should put you on the right lines. Don't believe you have to releaseKey() either when typing. I might be mistaken however and referring to another function.

 

This is awesome thanks but still have the same problem of it not actually typing. Nothing shows up in the text box unless I manually type any knowledge on how to fix this? The loop is nice but my problem is it is not functioning/typing into the box

Link to comment
Share on other sites

17 hours ago, Nbacon said:

String AlphaNumericString = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"                                     + "0123456789"                                     + "abcdefghijklmnopqrstuvxyz";    for (int i = 0; i < n; i++) {              int index                  = (int)(AlphaNumericString.length()                          * Math.random());        getKeyboard().typeKey(AlphaNumericString                            .charAt(index));           sleep(random(x,y));         } 

OMG thank you so much it worked!!

Link to comment
Share on other sites

14 hours ago, Otterblast said:

This is awesome thanks but still have the same problem of it not actually typing. Nothing shows up in the text box unless I manually type any knowledge on how to fix this? The loop is nice but my problem is it is not functioning/typing into the box

 

14 hours ago, Otterblast said:

OMG thank you so much it worked!!

It wasn't typing due to me using the wrong function for typing as nBacon mentioned. Should have used getKeyboard.typeKey()

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