SRL Archive - SRL Archives

TypeSend2 / QwertyKeys


FrÕzÑ_§ÕµL

2008-02-18 23:10:43

OK, so you all know I hate how the SRL SendKeys2 makes a random chr(250) yea? I mean pfft when does someone add a greek symbol or an l when they are ment to type an s?! So, I finally found an awesome way to get around my old 300+ lines of code hehe, all thanks to the idea of QwertyKeys. What it does is numbers the keys on a keyboard according to qwerty. so q is 1, w is 2 and m is 26.

QwertKeys(5) would return a t as that is 5th on a keyboard.

Yea yea, shut up with your crap frozen, wtf is wrong with chr?! Well, the whole thing of typing is a key press needs to be near the original. So I use

Insert(QwertyKeys(RandomRange(k - 2, k + 2)), Text, i);

So it inserts a key into the text, after a 90% chance of deleting the original, that is up to 2 keys each way of the original one.

So if it was 't' that was typed, QwertyKeys will return any of the following values: e, r, t, y, u.

^^ Getting somewhere now? OK, so here is my final code :

{*************************************************************************************************
Function QwertyKeys(Key : Integer) : String;
By: FrÕzÑ_§ÕµL.
Description: Orders CHR keycodes by qwerty. i.e. QwertyKeys(2) returns w.
*************************************************************************************************}

Function QwertyKeys(Key : Integer) : String;
Begin
Case Key of
1 : Result := CHR(113);
2 : Result := CHR(119);
3 : Result := CHR(101);
4 : Result := CHR(114);
5 : Result := CHR(116);
6 : Result := CHR(121);
7 : Result := CHR(117);
8 : Result := CHR(105);
9 : Result := CHR(111);
10 : Result := CHR(112);
11 : Result := CHR(97);
12 : Result := CHR(115);
13 : Result := CHR(100);
14 : Result := CHR(102);
15 : Result := CHR(103);
16 : Result := CHR(104);
17 : Result := CHR(106);
18 : Result := CHR(107);
19 : Result := CHR(108);
20 : Result := CHR(122);
21 : Result := CHR(120);
22 : Result := CHR(99);
23 : Result := CHR(118);
24 : Result := CHR(98);
25 : Result := CHR(110);
26 : Result := CHR(109);
end;
end;

{*************************************************************************************************
Function TypeSend2(Text: String; PercentPerfect, PercentMistake, MaxMistakes: Integer): Boolean;
By: FrÕzÑ_§ÕµL.
Description: Types Text Human-like, pressing random keys around the original. Results True if a
mistake is made.
*************************************************************************************************}

Function TypeSend2(Text: String; PercentPerfect, PercentMistake, MaxMistakes: Integer): Boolean;
var
i, k, NumMistakes : Integer;
s : String;

Begin
Text := Trim(Lowercase(Text));
if Random(101) >= PercentPerfect then
Begin
for i := 1 to Length(Text) do
Begin
if NumMistakes >= MaxMistakes + Random(2) then
Break;
if Random(101) <= PercentMistake then
Begin
Inc(NumMistakes);
Result := true;
s := Copy(Text, i, 1);
for k := 1 to 26 do
if s = Chr(96 + k) then
Begin
if Random(101) > 10 then
Delete(Text, i, 1);
Insert(QwertyKeys(RandomRange(k - 2, k + 2)), Text, i);
end;
i := i + randomrange(2, 5);
end;
end;
end;
Typesend(Text);
end;

The use of this would be
TypeSend2('lol', 33, 10, 5);

Harry

2008-02-18 23:12:57

Woah, that looks cool. It would suck if you tried to use LoginPlayer with this though :)

Good work!

FrÕzÑ_§ÕµL

2008-02-18 23:14:58

Lol well you would use normal TypeSend for LoginPlayer, or set PercentPerfect to 100 :p

ZOMG you actually like it? Nobody likes my ideas normally :(

Harry

2008-02-18 23:18:47

No, I am just spamming :rolleyes:
Of course I like it, not many humans type perfectally onto RS, I am lucky I use FireFox to browse the forums or my posts would be all like this:

if i dint use firefoox alls my postz wood be bad speelt

Very good anti-ban :)

Smartzkid

2008-02-18 23:22:41

Sorry to say, but there's still a shorter way to do it…

EDIT: Sorry guys, was working on writing the code and didn't think to explain myself. PM'ed Frozn_Soul, will post finished code tomorrow. Frozn has the code if you want to see it; basically bullzeye's idea, but using strings instead of arrays.

FrÕzÑ_§ÕµL

2008-02-18 23:28:18

And once again my idea is shredded in seconds.

Whats that Smartzkid?

bullzeye95

2008-02-18 23:29:24

Smartz, could you say your idea?

And I'll say a method I just thought of… you could use a 2d array of char, and do it like this:
A piece of your keyboard looks like this:
QWER
ASDF
ZXCV
This would be
S[1]:= ['q', 'w', 'e', 'r'];
S[2]:= ['a', 's', 'd', 'f'];
S[3]:= ['z', 'x', 'c', 'v'];
but you'd just change it to the whole keyboard to use it… it could be used like
if(IFeelLikeMessingUp)then
TehString[someRandomIndex]:= S[WhateverIndexTheLetterIsOn - Random(2) + Random(2)][WhateverIndexTheLetterIsOn - Random(2) + Random(2)]

FrÕzÑ_§ÕµL

2008-02-18 23:32:20

Ah yes that is a very good idea indeed ;) maybe I'll work on it later.

bullzeye95

2008-02-19 00:26:48

Well, this is what I just did out of extreme boredom :p
program New;
var
S: String;

procedure GetChrPos(C: Char; Arr: Array of Array of Char; var x, y: Integer);
begin
for x:= 1 to High(Arr) do
for y:= 0 to High(Arr[x]) do
if(Lowercase(C) = Arr[x][y])then
exit;
x:= -1;
y:= -1;
end;

function MessUpLetter(C: Char): Char;
var
Keys: Array [1..4] of Array of Char;
S: String;
I, x, y: Integer;
begin
SetLength(Keys[1], 13);
SetLength(Keys[2], 13);
SetLength(Keys[3], 11);
SetLength(Keys[4], 10);
S:= '`1234567890-=qwertyuiop[]\asdfghjkl;''zxcvbnm,./';
for I:= 1 to 13 do
Keys[1][I - 1]:= S[I];
for I:= 1 to 13 do
Keys[2][I - 1]:= S[I + 13];
for I:= 1 to 11 do
Keys[3][I - 1]:= S[I + 26];
for I:= 1 to 10 do
Keys[4][I - 1]:= S[I + 37];
GetChrPos(C, Keys, x, y);
if(x = -1)then exit;
try
if(Uppercase(C) = C)then
if(Lowercase(C) <> C)then
I:= -1;
C:= Keys[x + Random(2) - Random(2)][y + Random(2) - Random(2)];
if(I = -1)then
if(Lowercase(C) = C) xor (Uppercase(C) = C)then
C:= chr(ord(C) + 32);
except
end;
Result:= C;
end;

procedure MessUpString(var S: String);
var
I: Integer;
begin
for I:= 1 to Length(S) do
if(RBoolEx(15))then
S[I]:= MessUpLetter(S[I]);
end;

begin
S:= 'HHHHH';
MessUpString(S);
writeln(S);
end.
It messes up with capitals and symbols…

FrÕzÑ_§ÕµL

2008-02-19 00:37:33

Lol so basically it is no different to the SendKeys2?

bullzeye95

2008-02-19 00:44:14

It is. It uses a 2d array of char to recreate the layout of the keyboard, so it can "mess up" and press a key to the top, bottom, side, or diagonal to the key it's supposed to type. It just needs some work…

Smartzkid

2008-02-19 01:00:06

function RealisticType(text: string): integer;
//By Smartzkid, Created for Frozn_Soul, returns ratio of errors to correctly typed characters
var //Function Consts (vars because I needed strings for the alphabet and I wanted to keep all settings in one place, so the ints are here, too)
ERR_MAX, ERR_MIN, ERR_PROB, ERR_SIZE: integer;
ALPHA_LOW, ALPHA_HIGH, ALPHA_ALL: string;
var
i, j, txtLength, totalErrors, currChar: integer;
finaltxt, possibleChars: string;
begin
//Function Consts
ERR_MAX := 10; //Total error ratio; 1 error per ERR_MAX characters max
ERR_MIN := 0; //Total error ratio; 1 error per ERR_MIN characters min; 0 to disable
ERR_PROB := 15; //Average error ratio; 1 error per ERR_PROB characters average
ERR_SIZE := 1; //Max amount of keys to be off by; if the correct character is 'T', it can only give another character ERR_SIZE chars away from 'T'
ALPHA_LOW := '1234567890-= qwertyuiop[]\ asdfghjkl;'' zxcvbnm,./'; //' ' stands for new line of keys
ALPHA_HIGH:= '!@#$%^&*()_+ QWERTYUIOP{}| ASDFGHJKL:" ZXCVBNM<>?';
ALPHA_ALL := ALPHA_LOW + ' ' + ALPHA_HIGH;

totalErrors := 1; //Must be 1 to avoid a 'divide by 0' error
finalTxt := text;
txtLength := Length(text);
for i := 1 to txtLength do
if(Round(txtLength / totalErrors) - 1 > ERR_MAX)then //Ratio is off by -1 to help offset the error addressed on line 21
if(Random(ERR_PROB) = 0)then
begin
if(text[i] = ' ')then
Continue;
currChar := Pos(text[i], ALPHA_ALL);
possibleChars := Copy(ALPHA_ALL, currChar - ERR_SIZE, ERR_Size * 2 + 1);
if(Pos(' ', possibleChars) <> 0)then //to keep from hitting a key on the other side of the keyboard up or down by one row (ie: p -> a)
begin
for j := Pos(' ', possibleChars) to Length(possibleChars) do
if(possibleChars[j] = ' ')then
begin
Delete(possibleChars, j, Length(possibleChars) - j);
j := Length(possibleChars); //To break out of the loop; break was being retarded.
end;
for j := Pos(' ', possibleChars) downto 1 do
if(possibleChars[j] = ' ')then
begin
Delete(possibleChars, 1, j);
j := 1; //To break out of the loop; break was being retarded.
end;
end;
finalTxt[i] := possibleChars[random(Length(possibleChars)) + 1];
Inc(totalErrors);
end;
TypeSend(finalTxt);
if(totalErrors = 1)then
result := 0
else
result := txtLength / (totalErrors - 1);
end;

Could be improved, but it does it's job. Note that ERR_MIN is not implemented. This is all I'll do tonight, might work on it tomorrow if I'm asked to.