Sendkeys in MFC?
-
How would one go about sending keystrokes to a specific (not necessarily active) window? I have been working on this for awile, so any help would be appreciated. -Dev578
If you have access to the window (either a
CWnd
pointer or anHWND
), you could useSendMessage()
to send it messages simulating keystrokes (eg:WM_KWYDOWN
,WM_KEYUP
,WM_LBUTTONDOWN
,WM_LBUTTONUP
,WM_LBUTTONDBLCLK
). /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com -
How would one go about sending keystrokes to a specific (not necessarily active) window? I have been working on this for awile, so any help would be appreciated. -Dev578
Here's how I did it. I had a window "PCTV Vision" that I had to send ALT-R. I used a tool simillar to Spy++, it comes with Borland Delphi 3 and it is called Winsight32. With WInsight I selected that window and I started logging all the messages that went to that window. Then I made it active and pressed ALT-R from the keyboard. I returned to WInsight32 and looked in the message log. I found there a WM_COMMAND which he recognized as "Accelerator". I shamelessly copied the WParam and Lparam and pasted it in my program which sounds like PostMessage(hwnd,WM_COMMAND,stolen_WPARAM,stolen_LPARAM); The good part is that it works!!! ;-) :-) I never tried Spy++ because I haven't installed Visual Studio Completely and it isn't installed.