You could get the currently active window by calling GetForegroundWindow. Then use PostMessage to post keyboard messages to the window.