Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Send Keys to another App's edit box

1,340 views
Skip to first unread message

Larry Adams

unread,
Jul 13, 2000, 3:00:00 AM7/13/00
to
I'm looking for a way to eneter text into another app's edit box (It's
a logon popup box). I know the control's handle, so I tried using the
API function SendMessage. That didn't work for me, because the message
parameter for that function is of the cardinal type. I need to enter
text followed by 3 carriage returns. Is there a reasonable way to do
this with Delphi 5?


Lee J. Moore

unread,
Jul 13, 2000, 3:00:00 AM7/13/00
to

"Larry Adams" <sky...@flash.net> wrote in message
news:8kjhu9$do...@bornews.borland.com...

> I need to enter
> text followed by 3 carriage returns. Is there a reasonable way to do
> this with Delphi 5?

Well as long as you have the handle to the edit control:

SendText := 'This string should be sent to an edit control' +#13+#13+#13+
'Three carriage returns just took place!';
For Count := 1 to length(SendText) do
SendMessage(Wnd, WM_CHAR, Ord(SendText[Count]), 0 );

Hope that helps.

Best regards
--
L.J. - UK
ICQ: 42252330
Remove the monarchy to email me
--
Please do not request support for OP (Delphi),
Java, C++ or PHP by private email or ICQ.

Babür Şaylan

unread,
Jul 13, 2000, 3:00:00 AM7/13/00
to
Did u try Keybd_Event command?

Larry Adams wrote in message <8kjhu9$do...@bornews.borland.com>...


>I'm looking for a way to eneter text into another app's edit box (It's
>a logon popup box). I know the control's handle, so I tried using the
>API function SendMessage. That didn't work for me, because the message

>parameter for that function is of the cardinal type. I need to enter

Oracle At Delphi

unread,
Jul 13, 2000, 3:00:00 AM7/13/00
to
Here is a routine that simplifies sending a keystroke to a known
window handle.

procedure SendKey(hWnd: THandle; KeyStroke: Word);
begin
PostMessage(hWnd, WM_SETFOCUS, 0, 0);
PostMessage(hWnd, WM_KEYDOWN, KeyStroke, 0);
PostMessage(hWnd, WM_KEYUP, KeyStroke, 0);
end;

Now lets add a routine to send a string:

procedure SendString(hWnd: THandle; S: String);
var I: Integer;
begin
For I := 1 to Length(S) do SendKey(hWnd, S[I]);
SendKey(hWnd, VK_RETURN); // Send a Carriage Return
end;

I use postmessage, you should avoid SendMessage in this situation
because of its send and wait nature, whereas PostMessage just
posts the message in that windows processing queue.
Hope this helps.


0 new messages