Sending keys to active window.

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Feb 2005
Posts: 12
Reputation: Sam Lehman is an unknown quantity at this point 
Solved Threads: 0
Sam Lehman Sam Lehman is offline Offline
Newbie Poster

Sending keys to active window.

 
0
  #1
Sep 24th, 2005
I'm making a program which sends a specified line of text to the active window when you press a specified hotkey.

I've figured out how the hotkey part, but have no idea on how to send the text to the active window.

does anyone give me some ideas on this?

i'm using visual C++ .net


thanks
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 219
Reputation: BountyX is an unknown quantity at this point 
Solved Threads: 7
BountyX's Avatar
BountyX BountyX is offline Offline
Code Guru

Re: Sending keys to active window.

 
1
  #2
Sep 26th, 2005
Use PostMessage() . It will add your message to the the recieving windows message que.

(SendMessage is to be used only within the same thread).

Also, check out SendThreadMessage considering that PostMessage returns immediately so you can't get the return code from the message.

You may need the window's HWND as a parameter. To get the target process HWND try FindWindow or module walk through a list of process id's then get the HWND from the id.

If the recieving window is already active, you can do the following using keybd_event:

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

If you have the target process HWND, then you can set the window acive then use keybd_event (however it is better to use PostMessage if you have the hwnd -- that way if focus is somehow interupted it will not cause any problem)

For information on function prototypes reference msdn.com and search for the function name or keyword (i.e. PostMessage, keybd_event, module walking, etc)
A Hacker's Mind:
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes..." - J.D.Salinger
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC