SRL Archive - RS3 Help

KeyDown not working?


Ian

2014-03-22 22:57:15

I tried using KeyDown and KeyUp for dropping things from the actionbar in my script, but they had no effect.

To try to narrow down the problem I used this test script in a new Simba tab:

program new;
begin
KeyDown(31);
WriteLn(isKeyDown(31));
Wait(1000);
KeyUp(31);
end.

The blinky-text-thing was in the Simba script so it would type "11111111111111111111111" when I pressed play but nothing typed.

isKeyDown resulted true though, so I'm not sure why it didn't type.

Does this test work for any of you?

Frement

2014-03-22 22:58:49

Can't you use TypeSend?

EDIT: Or TypeByte to be exact.

Ian

2014-03-22 23:01:44

From: Frement
Can't you use TypeSend?

EDIT: Or TypeByte to be exact.


If I'm correct that would simulate (repeated) tapping of the key which isn't what I want. So yes, I could, but it's not quite what I was trying to do.

Frement

2014-03-22 23:10:13

program new;

var
StartTime: Integer;

begin
Sleep(5000);
StartTime := GetSystemTime;
while (GetSystemTime - StartTime < 5000) do begin
KeyDown(VK_A);
Sleep(10);
end;
KeyUp(VK_A);
end.

EDIT: And you might want to do something like this:
program new;

var
StartTime: Integer;
FirstWait: Boolean;

begin
Sleep(5000);
StartTime := GetSystemTime;
FirstWait := True;
while (GetSystemTime - StartTime < 5000) do begin
KeyDown(VK_A);
if (FirstWait) then begin
Sleep(800)
FirstWait := False;
end else
Sleep(50);
end;
KeyUp(VK_A);
end.

riwu

2014-03-22 23:29:05

I think it's a bug with the rs client that sometimes the client will lose keyboard focus.
Several times i've to minimize and reclick the client to regain keyboard focus.

Frement

2014-03-22 23:33:37

From: riwu
I think it's a bug with the rs client that sometimes the client will lose keyboard focus.
Several times i've to minimize and reclick the client to regain keyboard focus.


OP's snippet won't work for notepad either.

riwu

2014-03-22 23:54:25

Oh, i think for some reason for the newer versions of simba you have to use the virtual key constants.
Try KeyDown(VK_1);

Ian

2014-03-23 12:04:56

From: riwu
Oh, i think for some reason for the newer versions of simba you have to use the virtual key constants.
Try KeyDown(VK_1);

Ok, tried

program new;
begin
KeyDown(VK_1);
WriteLn(isKeyDown(VK_1));
Wait(10000);
KeyUp(VK_1);
end.
with the notepad to type in and it typed "1" once but only once. I tried removing the isKeyDown as well so it was just the down, wait, and up, but still only pressed it once.

Frement

2014-03-23 12:06:00

From: BMWxi
Ok, tried

program new;
begin
KeyDown(VK_1);
WriteLn(isKeyDown(VK_1));
Wait(10000);
KeyUp(VK_1);
end.
with the notepad to type in and it typed "1" once but only once. I tried removing the isKeyDown as well so it was just the down, wait, and up, but still only pressed it once.


I already posted working code, did you have problems with it?

Ian

2014-03-23 12:08:22

From: Frement
program new;

var
StartTime: Integer;

begin
Sleep(5000);
StartTime := GetSystemTime;
while (GetSystemTime - StartTime < 5000) do begin
KeyDown(VK_A);
Sleep(10);
end;
KeyUp(VK_A);
end.

EDIT: And you might want to do something like this:
program new;

var
StartTime: Integer;
FirstWait: Boolean;

begin
Sleep(5000);
StartTime := GetSystemTime;
FirstWait := True;
while (GetSystemTime - StartTime < 5000) do
begin
KeyDown(VK_A);
if (FirstWait) then begin
Sleep(800)
FirstWait := False;
end else
Sleep(50);
end;
KeyUp(VK_A);
end.


Both of those worked fine for me, thanks. Odd my first example didn't work though…

E: Both of these are repeatedly pressing KeyDown, so does keydown not hold the key down? If so what is the purpose of KeyUp?