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

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)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.