In a project you need to call a third-party console program for recording, the recording completed need to hit a return to end the recording. The console program is hidden in the background, using Spy + + to find its window name, you can find its handle via FindWindow hwnd, which I thought can be used SendMessage And PostMessage started sending messages.
::P ostmessage (hwndffmpeg,wm_keydown,vk_return,0);//Invalid
::P ostmessage (hwndffmpeg,wm_keyup,vk_return,0);//invalid
But the fact is not, the online find may be the last parameter of the problem, but do not know what to fill
After understanding the scan code, has obtained the scanning code function Mapvirtualkey, through this function name finally found the desired data
The following are summarized below:
DWORD Dwvkfkeydata;
WORD dwscancode =mapvirtualkey (vk_f1,0);//vk_f1
dwvkfkeydata = 1;
Dwvkfkeydata |= dwscancode<<16;
Dwvkfkeydata |= 0<<24;
Dwvkfkeydata |= 1<<29;
Press
::P ostmessage (HWND) (0x203f0,wm_keydown,vk_f1,dwvkfkeydata);
Bounce Up
dwvkfkeydata |= 3 << 30;
The Dwvkfkeydata parameter is a 8-digit 16 binary (example: 0x412e0001)
(Personal understanding) The following bit is a binary number, 0-15 bits equivalent to 16 decimal low 4 bits, that is, 0001 in the above example, with binary to show is 0000 0000 0000 0001
0-15-bit: Specifies the number of repetitions of the current message. The value is the number of times the user presses the key to automatically repeat, but the number of repetitions does not accumulate
16-23-bit: Specifies its scan code, whose value is dependent on the OEM manufacturer
24-bit: Specifies whether the button is an extension button, the so-called extension button is Ctrl,alt, such as, if the extension button, its value is 1, otherwise 0
25-28-bit: Reserved field, temporarily unavailable
29-bit: Specifies the context when the key is pressed, with a value of 1 indicating that the ALT key is down when pressing the key, and a value of 0 means that the WM_SYSKEYDOWN message is sent to the currently active window because no window has keyboard focus.
30-bit: Specifies the state before the key, and a value of 1 indicates that the key was pressed before the message was sent, and a value of 0 indicates that the key was lifted before the message was sent.
31-bit: Specifies its conversion state, and the value is always 0 for wm_syskeydown messages.
Microsoft Original: Http://msdn.microsoft.com/en-us/library/ms646280%28VS.85%29.aspx
Other references:
PostMessage send ALT key combination to Windows window
Analog keyboard keys