Solved

Question about "SendMessage" function

Posted on 1999-01-22
5
196 Views
Last Modified: 2010-04-02
Can the API call 'SendMessage' be used to emulate keystrokes?
   If so, what is the correct syntax(parameters) for doing this.

Thanks in advance
0
Comment
Question by:jamarlin
  • 2
  • 2
5 Comments
 
LVL 15

Accepted Solution

by:
Tommy Hui earned 20 total points
ID: 1184872
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
 
LVL 22

Expert Comment

by:nietod
ID: 1184873
If you wish to send keystrokes to the application with the focus, then the keybd_event() procedure is ussually easier to use.
0
 

Author Comment

by:jamarlin
ID: 1184874
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
 
LVL 22

Expert Comment

by:nietod
ID: 1184875
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
 

Author Comment

by:jamarlin
ID: 1184876
Thank you for your suggestions.
Both of you have been a great help to me!!

Thanks again.


0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
C++ - Convert a wString to char * 9 513
C++ assignment question 7 168
C++ standard library based binary archive format 6 91
Should CArray be used for a list of pointers in C++? 19 97
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now