Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending a virtual keystroke

Status
Not open for further replies.

DoctorC

Programmer
Jun 29, 2000
34
US
I want to send a message to a window in another program which will simulate actual keystrokes in the receiving program. The key combination I want to send is alt-enter.

I have tried:

PostMessage(hWnd, WM_SYSKEYDOWN, VK_RETURN, 1);

but I'm not getting the response I want. I have checked the HWND, and it is the correct window, but how can I send a key combination like this. Any ideas?

CN
 
If, by specifying the lParam as 1, you wanted to specify the context code "ALT Down", then that's not going to work. Context code is bit 29 of the lParam, not bit 0.
Greetings,
Rick
 
Thanks Rick, for your response. I am still not getting the behavior I need. I know that pressing the key combination "Alt-Enter" produces the desired effect in the target app. I have confirmed that posting a WM_CLOSE message will close the target app. I can also generate a Message Box in the target app by calling it from my source program with the HWND of the target app.

However, calling the following code does nothing:

LPARAM lParam = 536870912;
PostMessage(hWnd, WM_SYSKEYDOWN, VK_RETURN, lParam);


As I understand it, 536870912 is the decimal version of a number with the 29th bit set. What am I missing here?
Charlie
 
Seems ok to me. Have you tried sending that same message to a window you have "under control" (i.e. you can debug) and see waht happens there?
Greetings,
Rick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top