First of all, I would question the whole idea of feeding any data to an external application. Even though it can be appropriate in some very special product (such as system utilities), it could not be considered as a legitimate way of "integration". Processes are well isolated, and, if they are not designed for one or another mechanism of collaboration, forcing them to do one or another thing by simulation of user input will also be a kind of dirty business; you cannot expect reliable and maintainable results.
Besides, Windows messaging mechanism is not a reliable way of such simulation. This mechanism is Windows-specific, based on obsolete Windows architecture (when it comes to exchanging messages between different processes) and is not used by all applications. Controls don't have to be windowed controls, and, in case, for example, of WPF and other architectures based on DirectX, won't be.
The only universal way of simulation of user input is the Windows API
SendInput
:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646310%28v=vs.85%29.aspx[
^].
Is always works as expected just because its low level; it works pretty much as the device drivers do when they send raw input (drivers, at least in some Windows version, used the functions
keybd_event
and
mouse_event
which you should not use, because they have been superseded by
SendInput
). The usage is quite simple and always reliable, tested.
—SA