Author: Udo Nesshoever
How can I e.g. "type" programmatically in another application?
There are several methods to send keystrokes or characters to a WinControl. The
SetKeyboardState requires the control to have the focus but can send more (esp.
special) keys. The use of WM_CHAR message enables you to send characters even to a
hidden control unless you have found out the handle of it (there are a couple of
ways to find out a controls handle). Once you've got it, you can send messages to
I'm using this method for a little tool to "type" certain frequently used phrases
while posting to newsgroups.
I hardcoded the handle of the edit control of my favorite newsreader and now I have
a small and handy tool to type messages faster than ever.
1 2 procedure SendMsg(const h: HWND; const s: string);
3 var4 i: integer;
5 begin6 if h = 0 then7 Exit;
8 if Length(s) = 0 then9 Exit;
10 for i := 1 to Length(s) do11 begin12 if Ord(s[i]) in [9, 13, 32..254] then13 SendMessage(h, WM_CHAR, Ord(s[i]), 0);