I've used WIN32API calls in the past to simulate keystrokes without much trouble. Even now, at a superficial level, it seems to work. I'm using the Win32 SendMessage call to send a WM_KEYDOWN, WM_CHAR, WM_KEYUP message to an instance of Notepad.
And sure enough, whatever I send appears in Notepad.
But while using Spy++ to inspect the messages; I noticed that my sent Keystrokes were noticeably different than the keys I had actually typed or the ones created using Windows built-in on screen keyboard.
In Spy++ my single WM_KEYDOWN generates two lines:
<001> 00234 S WM_KEYDOWN nVirtKey:'W'.... <002> 00234 R WM_KEYDOWN Pressing the W key for real (or using the OnScreenKeyboard) generates only a single line
<003> 00234 P WM_KEYDOWN nVirtKey:'W'... If I expand these messages, I can see that 'S' represents Sent, R - 'Received', and P - 'Posted'.
Can anyone tell how I can more accurately simulate keyboard input programatically? I've matched the rest of the message (including the lParam value).