troubleshooting Question

Send keystrokes to another application

Avatar of Peter Kiers
Peter KiersFlag for Netherlands asked on
Delphi
4 Comments1 Solution231 ViewsLast Modified:
Hello there,

I have a component that sends keystrokes to another application.
And it works fine, but it can only sends characters, or a Carriage Return
or a TAB

Example:

SendKeys1.SendKeys(Chr(13));
SendKeys1.SendKeys(Chr(10));

But I want to send Function-Keys also!
And this example doesn't work.

SendKeys1.SendKeys(Chr(VK_F5));

This is the code that sends the keys:

procedure TSendKeys.SendKeys(buffer: string);
var i:integer;
    w:word;
    D:DWORD;
    P:^DWORD;
begin
  P:=@D;
  SystemParametersInfo(                      //get flashing timeout on win98
         SPI_GETFOREGROUNDLOCKTIMEOUT,
         0,
         P,
         0);
  SetForeGroundWindow(fHandle);
  for i:=1 to length(buffer) do
  begin
    w:=VkKeyScan(buffer[i]);
    keybd_event(w,0,0,0);
    keybd_event(w,0,KEYEVENTF_KEYUP,0);
  end;
  SystemParametersInfo(                     //set flashing TimeOut=0
         SPI_SETFOREGROUNDLOCKTIMEOUT,
         0,
         nil,
         0);
  SetForegroundWindow(TWinControl(TComponent(Self).Owner).Handle);
                                            //->typecast working...
  SystemParametersInfo(                     //set flashing TimeOut=previous value
         SPI_SETFOREGROUNDLOCKTIMEOUT,
         D,
         nil,
         0);
end;

I have looked in Delphi Help for the explanation of:  keybd_event(w,0,0,0);
But I don't understand the parameters, could someone explain it to me.
     
Greetings,

Peter Kiers
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 4 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros