Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

send key press to other application in delphi

Posted on 2011-10-12
5
Medium Priority
?
2,467 Views
Last Modified: 2012-05-12
THe below code gets compiled, but it doesnt send the key press to the note pad. I have opened the note pad and kept as it is. can anyone help me..?


procedure TForm1.Button1Click(Sender: TObject);
var
  Window: hwnd;

begin
  Window := FindWindowA('notepad', nil); // Finds notepad.
  if Window <> 0 then
  begin
    keybd_event(Ord('B'), 0, 0, 0);
  end;
end;

Open in new window

0
Comment
Question by:jimsweb
5 Comments
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 36954201
you don't pass the window variable to the keybd_event
so it can never work
0
 
LVL 23

Expert Comment

by:Ferruccio Accalai
ID: 36954387
You have to specify which keyboard_event  are you passing.
Any keystroke is composed by a keydown and a Keyup

So to send the B key you have to do

keybd_event(VkKeyScan('B'), 1, 0, 0); //key down
keybd_event(VkKeyScan('B'), 1, KEYEVENTF_KEYUP, 0); //key up

0
 
LVL 19

Expert Comment

by:Thommy
ID: 36955100
Try unit sndkey32...

How to send keystrokes to another application (a better one)
http://www.delphi3000.com/articles/article_1617.asp?SK=
0
 
LVL 19

Accepted Solution

by:
Thommy earned 2000 total points
ID: 36955119
You can also use SendMessage(...)

Send keys to another application
http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_22043534.html
0
 
LVL 8

Author Closing Comment

by:jimsweb
ID: 36955478
Thanks..
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Integration Management Part 2
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

810 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