Recent

Author Topic: Sending keys with PutKeyEvent  (Read 903 times)

spigor

  • New Member
  • *
  • Posts: 10
Sending keys with PutKeyEvent
« on: March 03, 2024, 04:31:38 pm »
Hi
I'm trying to send keys with PutKeyEvent to add some characters in front of user's input. The user will have to enter "o5XXXX", so I want to write "o5" for him in the input line, so the user has only to add the "XXXX" and press 'enter'. The code would then use 'readln' to read the entire "o5XXXX" into a string variable.
I found with GetKeyEvent that the character "o" assigns to variable of type TKeyEvent a value of 50337903. I tried to send that with PutKeyEvent, typecast that value into Cardinal and LongInt and then send that, and use the TranslateKeyEvent, but it all failed.
Any guidance on the above would be much appreciated.
Thanks!

jamie

  • Hero Member
  • *****
  • Posts: 6131
Re: Sending keys with PutKeyEvent
« Reply #1 on: March 03, 2024, 04:35:51 pm »
in your app or are you trying to infiltrate other apps?
The only true wisdom is knowing you know nothing

spigor

  • New Member
  • *
  • Posts: 10
Re: Sending keys with PutKeyEvent
« Reply #2 on: March 03, 2024, 04:36:50 pm »
It's just in my simple text based app.

jamie

  • Hero Member
  • *****
  • Posts: 6131
Re: Sending keys with PutKeyEvent
« Reply #3 on: March 03, 2024, 04:58:03 pm »
I don't know if I would like to show you how to insert into the systems buffer, however, you can simply do a write('o5') prior to the READLN;

 It will prevent the user from backspacing it but after the user presses ENTER, you can add the "o5" to the string.

Code: Pascal  [Select][+][-]
  1.  Var
  2.    A:String;
  3. begin
  4.  write(output, 'o5');
  5.  Readln(A);
  6.  readln;
  7. end.            
  8.  
« Last Edit: March 03, 2024, 04:59:37 pm by jamie »
The only true wisdom is knowing you know nothing

spigor

  • New Member
  • *
  • Posts: 10
Re: Sending keys with PutKeyEvent
« Reply #4 on: March 03, 2024, 06:16:39 pm »
The user might have to change the "o5" to something different on some occasions.

jamie

  • Hero Member
  • *****
  • Posts: 6131
Re: Sending keys with PutKeyEvent
« Reply #5 on: March 03, 2024, 07:58:28 pm »
I'll give you something to look forward to, you'll need to decode the rest of it  8)

Code: Pascal  [Select][+][-]
  1. program Project1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   {$IFDEF UNIX}{$IFDEF UseCThreads}
  7.   cthreads,
  8.   {$ENDIF}{$ENDIF}
  9.   Classes,windows,types
  10.   { you can add units after this };
  11.  Var
  12.    A:String;
  13. Procedure InsertInputString(S:String);
  14. Var
  15.   I:Integer;
  16.  Begin
  17.    FOr I := 1 to Length(S) do
  18.     Begin
  19.       keybd_event(Byte(S[I]),0,0,0);
  20.       keybd_event(Byte(S[I]),0,KEYEVENTF_KEYUP,0);
  21.     end;
  22.  end;
  23.  
  24. begin
  25.  InsertInputString('O5');
  26.  ReadLn(A);
  27.  readln;
  28. end.
  29.  
  30.  
The only true wisdom is knowing you know nothing

spigor

  • New Member
  • *
  • Posts: 10
Re: Sending keys with PutKeyEvent
« Reply #6 on: March 05, 2024, 06:48:36 pm »
Thank you!!!
I will have a chance to test it end of this week, but it already looks very informative to me.

spigor

  • New Member
  • *
  • Posts: 10
Re: Sending keys with PutKeyEvent
« Reply #7 on: March 11, 2024, 10:11:19 am »
@jamie
It worked very well. Thank you once again for showing me the right direction!!!

 

TinyPortal © 2005-2018