943,545 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 8730
  • C++ RSS
Sep 24th, 2005
0

Sending keys to active window.

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Sam Lehman is offline Offline
12 posts
since Feb 2005
Sep 26th, 2005
1

Re: Sending keys to active window.

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)
Reputation Points: 28
Solved Threads: 9
Posting Whiz in Training
BountyX is offline Offline
222 posts
since Mar 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Binary Code
Next Thread in C++ Forum Timeline: copy constructors





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC