Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to Send characters to another control (in any application) Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
23-Jun-03
Category
Win API
Language
Delphi 3.x
Views
181
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Udo Nesshoever 

How can I e.g. "type" programmatically in another application?

Answer:

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 
it. 

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   var
4     i: integer;
5   begin
6     if h = 0 then
7       Exit;
8     if Length(s) = 0 then
9       Exit;
10    for i := 1 to Length(s) do
11    begin
12      if Ord(s[i]) in [9, 13, 32..254] then
13        SendMessage(h, WM_CHAR, Ord(s[i]), 0);
14    end;
15  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC