Getting the focused window in other program

Giganews Newsgroups
Subject: Getting the focused window in other program
Posted by:  Mike Warren (miwa-not-this-b…
Date: Thu, 29 Jul 2010

I want to create a program that sends keystrokes to whatever window
is currently focused and able to receive keyboard input.

At this stage all then receiving programs will also be created by me,
so I /could/ use custom messages, but it would be nice if I did things
in a standard way in case I ever need to control another program.

Is is reliable just to post messages to the handle obtained with

I assume I would need to post WM_KEYDOWN, WM_KEYUP, and WM_CHAR (when
appropriate) messages?

I don't need to send any system keys, but I do need to send, left, right,
page up etc. as well as character keys.

- Mike