1

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).

1 Answer 1

2

I think you will need to use PostMessage rather than SendMessage. It's pretty much the same other than the way that the message is delivered to the reciever.

http://msdn.microsoft.com/en-us/library/windows/desktop/ms644944%28v=vs.85%29.aspx

Sign up to request clarification or add additional context in comments.

1 Comment

Haha - that is exactly what I needed. Will accept once I can.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.