Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending keystrokes to exe opened with ShellExecuteEx 1

Status
Not open for further replies.

biot023

Programmer
Nov 8, 2001
403
GB
Hallo. I've been looking at loads of examples of code using ShellExecuteEx, but I can't find any examples where an exe is opened & keystrokes are sent to it. I know this is possible in VB with SendKeys, but far prefer working with C++.
Does anybody know if this is possible & what command(s) to use? In VB you use SendKeys with the handle returned from the call to execute the exe.

Any help gratefully received.

Cheers,
Douglas JL. If it don't make you laugh, it ain't true.
 
Hey, I just had an idea on how to do this, but I'm at school now.. I'll have a look at some other posts when I get home then post my idea (it has something to do with keybd_event and the fact that ShellExecute returns a HINSTANCE [pc3]
 
Anything you can think of, man - I'm stumped. If it don't make you laugh, it ain't true.
 
I remember seeing an example of finding a Notepad window and sending keypresses to it, I imagine you could do the same but using ShellExecute to get the window handle.
I'm looking for this example now... [Thanks in advance|Hope I helped you]
Exodus300
World-Wide Alliance of Evil and Twisted People
[red]"Experimentation by Example is the best learning tool" - Exodus300[/red]
[pc3]
 
I remember the example I saw simply found a window titled "Notepad" and sent it a message to come to the front, then used keybd_event to simulate keypresses, which would go to the Notepad window because it was in front.

It works, but it's a pretty strange way of doing it. I guess it really depends on what your program is supposed to do.


I can't find the example now, but I'll keep looking for you.

[Thanks in advance|Hope I helped you]
Exodus300
World-Wide Alliance of Evil and Twisted People
[red]"Experimentation by Example is the best learning tool" - Exodus300[/red]
[pc3]
 
Cheers, man.
That sounds like exactly what I need.
Thanks for looking into it.

Douglas JL

If it don't make you laugh, it ain't true.
 
Lol I JUST found it...


void __fastcall TForm1::Button1Click(TObject *Sender)
{
// Get the handle of the window
HANDLE notepad = FindWindow("Notepad", 0);
if(notepad != NULL)
{
// Activate Notepad
BringWindowToTop(notepad);
// Send key
keybd_event('A', 0, 0, 0);
keybd_event('A', 0, KEYEVENTF_KEYUP, 0);
}
else
{
ShowMessage("Notepad not opened!");
}
} [Thanks in advance|Hope I helped you]
Exodus300
World-Wide Alliance of Evil and Twisted People
[red]"Experimentation by Example is the best learning tool" - Exodus300[/red]
[pc3]
 
That's fantastic, thanks.
Cheers for looking into it for me - well worth a star!

Douglas. If it don't make you laugh, it ain't true.
 
Thanks!

(I can't believe how long it took me to find that - it was even in my Favourites list! Maybe I should go to bed...:)) [Thanks in advance|Hope I helped you]
Exodus300
World-Wide Alliance of Evil and Twisted People
[red]"Experimentation by Example is the best learning tool" - Exodus300[/red]
[pc3]
 
Well, cheers again & goodnight! If it don't make you laugh, it ain't true.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top