How can I send a certain key to a certain application? (simulate keyboard)
-
I have a TV tuner with a crappy app that controls it and no scheduler to record shows. I would write my own app to schedule the startup of the crappy app and the ALT-R to begin record and again to stop it. Unfortunately all I know is that I have to send the app a certain message. Any clues guys? :-) Thank you, Andrei. LATER UPDATE: So I found you can use: PostMessage(hwnd, WM_CHAR, WPARAM('^'), LPARAM(M)); for CTRL-M But there appears 2 more questions in my mind: a) How do you do it for ALT-R or ALT-F4? Any general rule? b) How do you determine the handle of the window you want to send it to? Mine has "PCTV Vision" in the title. Any chance you have to use FindWindow? TNX!
-
I have a TV tuner with a crappy app that controls it and no scheduler to record shows. I would write my own app to schedule the startup of the crappy app and the ALT-R to begin record and again to stop it. Unfortunately all I know is that I have to send the app a certain message. Any clues guys? :-) Thank you, Andrei. LATER UPDATE: So I found you can use: PostMessage(hwnd, WM_CHAR, WPARAM('^'), LPARAM(M)); for CTRL-M But there appears 2 more questions in my mind: a) How do you do it for ALT-R or ALT-F4? Any general rule? b) How do you determine the handle of the window you want to send it to? Mine has "PCTV Vision" in the title. Any chance you have to use FindWindow? TNX!
I like using Spy++ (part of the Visual Studio suite). It has several input methods - type the dialog name, 0x handle number, or select a cross-hair pointer and zap the window you want info on. Johnny
-
I have a TV tuner with a crappy app that controls it and no scheduler to record shows. I would write my own app to schedule the startup of the crappy app and the ALT-R to begin record and again to stop it. Unfortunately all I know is that I have to send the app a certain message. Any clues guys? :-) Thank you, Andrei. LATER UPDATE: So I found you can use: PostMessage(hwnd, WM_CHAR, WPARAM('^'), LPARAM(M)); for CTRL-M But there appears 2 more questions in my mind: a) How do you do it for ALT-R or ALT-F4? Any general rule? b) How do you determine the handle of the window you want to send it to? Mine has "PCTV Vision" in the title. Any chance you have to use FindWindow? TNX!
For your b) question, here's how:
HWND hwnd = ::FindWindow(NULL,"PCTV Vision");
Then you can call PostMessage usinghwnd
For alt+f4, you could just use::PostQuitMessage(0);
I am not sure at all on how to send (i.e: CTRL+M), but ifPostMessage(hwnd, WM_CHAR, WPARAM('^'), LPARAM(M));
works, thenPostMessage(hwnd, WM_CHAR, WPARAM('!'), LPARAM(R));
would do the job. One more thing. If you are coding an MFC application, you will need to add ' :: ' in front of your PostMessage's and FindWindow's, since you want to play withHWND
values, and notCWnd
Michael