PDA

View Full Version : KeyDown not working?



Ian
03-23-2014, 02:57 AM
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
03-23-2014, 02:58 AM
Can't you use TypeSend?

EDIT: Or TypeByte to be exact.

Ian
03-23-2014, 03:01 AM
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
03-23-2014, 03:10 AM
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
03-23-2014, 03:29 AM
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
03-23-2014, 03:33 AM
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
03-23-2014, 03:54 AM
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
03-23-2014, 04:04 PM
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
03-23-2014, 04:06 PM
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
03-23-2014, 04:08 PM
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?