Link to home
Start Free TrialLog in
Avatar of rvjr
rvjr

asked on

sending messages to windows

Hi,

I'm trying to build an application, in which you can press some keys, and then, send the key to an application by typing in its window title. I have written an event handler attached to application.onmessage, which handles all keyup and keydown messages, it stores the given tMsg-Object in a global array, called Msgs. When clicking on the SendBtn, I send the messages in the right order TimesEdit.Value-times to the window with TitleEdit.Text in the titlebar.

Example: User presses a;b;c; and wants these key to be sent twice to a window called "untitled - notepad", the notepad editfield should then contain "abcabc".

here's the code:

procedure TMainForm.SendBtnClick(Sender: TObject);
  var I: integer;
      H, N, X: Cardinal;
begin
  H := GetHandleFromWindowTitle (TitleEdit.Text);
  N := TimesEdit.Value;
  X := 0;
//  SetActiveWindow (H);
  try
    while (not Cancel) and (X < N)do begin
      for I := 0 to high (Msgs) do begin
        PostMessage (H, Msgs [I].message, Msgs [I].wParam, Msgs [I].lParam);
//        DefWindowProc (H, Msgs [I].message, Msgs [I].wParam, Msgs [I].lParam);
//        SendMessage (H, Msgs [I].message, Msgs [I].wParam, Msgs [I].lParam);
      end;
      Application.ProcessMessages;
      Inc (X);
    end;
  finally
//    SetActiveWindow (Handle);
  end;
end;

I tried SendMessage, DefWindowProc and PostMessage, and none of them seem to work (no error, but also no effect). I have the right handle (using findwindow).

What could be wrong? None of the applications i tested this with seems to react to the messages. Do they get the messages at all?

Thanks
Rainer jr.
ASKER CERTIFIED SOLUTION
Avatar of stanko1
stanko1

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rvjr
rvjr

ASKER

Yes, I know how to use the functions in sendkeys.pas, but I am trying to build something on my own. the question is just: why does it not work, to "forward" all key messages to the other window?
rvjr:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:
       accept stanko1's answer
Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Merry Christmas and happy new year!

kacor
EE Cleanup Volunteer