Please use something which was proven to work well:
SendInput
:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646310%28v=vs.85%29.aspx[
^].
You do it using P/Invoke, which is already done for you, here:
http://www.pinvoke.net/default.aspx/user32.sendinput[
^].
Note that
keybd_event
has been superseded with
SendInput
.
As to
SendMessage
, it can also be used but has a number of limitations. First of all, it can be used on a windowed control only. So, WPF would be out of question (note that you did not indicate the UI library you want to use, which is bad; it' a good idea to always indicate it, as well as your application type).
SendInput
is preferable, because it simulates the input on lower level, as if it was called by the input device driver, so it can be used universally.
Finally, I would like to warn against the use of input simulation. It can be important in some specific cases: playing keyboard (mouse) macro, development of programs testing UI, something like that. If you simply try to use it for UI development, it would be a big abuse.
—SA