OK, you have to do that yourself or call into the keyboard driver, but
PostKeybdMessage bypasses most situations where you'd need to do it, anyway.
No, it sends the data through the input system, not 'directly' to a control,
although that is transparent to you. Typically, since you just want to send
the data without a lot of monkeying around, you'd do something like this for
non-control keys:
PostKeybdMessage( (HWND)-1, 0,
pshift[ 0 ],
len,
pshift,
&charbuf[ 0 ] )
pshift would be set to an array of KeyStateDownFlag. In this case, you
don't have to handle shift keys, etc. If the characters in charbuf are
"aAbBcC", they get sent just fine without any funny work with the shift key.
For things like Tab, Enter, etc, you have to use keybd_event(). For those,
you might do something of this nature:
keybd_event( VK_TAB, VK_TAB, 0, 0 );
keybd_event( VK_TAB, VK_TAB, KEYEVENTF_KEYUP, 0 );
to send the character.
I suppose that, if you are doing this wedging from the same program that
already has the focus, there's little benefit to working with
PostKeybdMessage and keybd_event. Why not just set the .Text property? If,
as in my case, you are running as a service and wedging, say, the input
found at one or more serial ports into the keyboard stream, this is far
better than trying to figure out what control has focus and what to do about
sending it characters.
Paul T.