Question about "SendMessage" function

Can the API call 'SendMessage' be used to emulate keystrokes?
   If so, what is the correct syntax(parameters) for doing this.

Thanks in advance
jamarlinAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Tommy HuiConnect With a Mentor EngineerCommented:
Generally, you can use

  SendMessage(hwnd, WM_CHAR, virtKey, 0);

for most keys. However, certain keys like SHIFT, require three SendMessages in sequence: WM_KEYDOWN, WM_CHAR, and WM_KEYUP.
0
 
nietodCommented:
If you wish to send keystrokes to the application with the focus, then the keybd_event() procedure is ussually easier to use.
0
 
jamarlinAuthor Commented:
The application that I am sending keystrokes to does not have the focus. In fact,
before I send keystrokes to that app, I used the API 'EnableWindow' to disable the application.
See, I dont want the user to be able to type in this application at all(at least not while I am
sending keystrokes to it).  This is the main reason why I am trying to see if SendMessage will work as oppposed to SendKeys. I had been using SendKeys to this point, but I seem to get errors(probably because the user was hitting keys on the keyboard while SendKeys was at work).  Any suggestions.
0
 
nietodCommented:
Dissabling the window may be a problem.  It may not recognize the keystrokes when disabled.

Also use Spy++ to make sure that you are sending the exact same key messages that are ordinarily send when a key is typed.  Make sure all the parameters are correct.  I would send just the key down and key up messages.  It will covert them to the WM_CHAR messages as needed.
0
 
jamarlinAuthor Commented:
Thank you for your suggestions.
Both of you have been a great help to me!!

Thanks again.


0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.