Simulate keystroke - Delphi

Asked

Viewed 131 times

1

Hello, I’m having trouble sending the keystroke in a game,

I’m using Delphi, I tested functions like:

  SendMessage(hdle_do_game, WM_KEYDOWN , ord('a'), 0);
   keybd_event(65,0,0,0);
SendMessage(hdle_do_game, WM_CHAR, ord('a'), 0);

and the game simply does not recognize in its interface, only in chatbox areas, however, the windows virtual keyboard works throughout the game

any suggestions? Grateful!

  • Good afternoon Daniel, try using keybd_event('Ord'), 0, KEYEVENTF_UNICODE, 0);

  • Thanks for the comment Pablo, I am using version 7 of Delphi, here was not declared the constant KEYEVENTF_UNICODE, but I noticed in internet routines that is equivalent to 4. So I started testing these parameters, to my surprise, I made a loop from 0 to 255, sending the instruction like this: keybd_event(1,i,1,0); the result was that the game reconhceu the keys I need, but it does not correspond to ASCII, it even makes sense since the game was developed in Coreia, I’ll try to find the Keys I need now...thanks for solving my problem

1 answer

1

Try using the Getasynckeystate(key) function of the winapi package. Windows:

procedure TForm2.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
   if isKeyPress(17) then begin
      showMessage('telcla Ctrl pressionada');
   end;

end;

function TForm2.IsKeyPress(const Key: integer): boolean;
begin
   Result := GetASyncKeyState(Key) <> 0;
end;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.