[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Send simulated KeyStroke ??

Posted on 2000-02-12
3
Medium Priority
?
1,088 Views
Last Modified: 2012-05-05
How can i send a keystroke to another application in Delphi ?
I have hWnd.
0
Comment
Question by:brain2000
3 Comments
 

Accepted Solution

by:
czyky earned 160 total points
ID: 2515043
Sending keys to another app in 3 or 4 easy steps.

You have the hWnd of the window.

1)
First, set focus to it using the SetForegroundWindow(hwnd); windows api call.

2) just in case, to give the system time to fully reset window focus, do a Application.ProcessMessages;

3)
send keys using the keybd_event() windows api call, as for example:

keybd_event(<Key>,0,0,0); sends a keydown to the focused app.

keybd_event(<key>,0,KEYEVENTF_KEYUP,0); sends a keyup to the app.

Sometimes just sending the keydowns is enough, but to be sure, you should send both a keydown and a keyup, as in:

keybd_event(Ord('A'),0,0,0);
keybd_event(Ord('A'),0,KEYEVENTF_KEYUP,0);

That sent an 'A' keystroke to the focused app.

Special keys can be sent by sending something like:

keybd_event(VK_F7,0,0,0);
keybd_event(VK_F7,0,KEYEVENTF_KEYUP,0);

to sends a F7 key. The VK_ codes are defined in windows.pas;

4) when you're down sending keys, you may want to return focus back to your app with another SetForegroundWindow(Self.hwnd);

Good luck and regards.
0
 
LVL 3

Expert Comment

by:bryan7
ID: 2515305
listenning
0
 

Author Comment

by:brain2000
ID: 2515576
It works fine, thankyou !
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
There may be issues when you are trying to access Outlook or send & receive emails or due to Outlook crash which leads to corrupt or damaged PST file. To eliminate the corruption from your PST file, you need to repair the corrupt Outlook PST file. U…
Suggested Courses

590 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question