In my program(C++, WinAPI), I wanted to simulate pressing some existing hotkeys set in other running programs. I know there is a SendInput function which simulates the keyboard input, but it seemed too much work as it needs to create a lot of structures for the keys.
I was trying use SendMessage or PostMessage with HWND_BROADCAST and WM_HOTKEY parameters. Neither worked.
The code looks like this:
WORD hotkey = MAKEWORD(MOD_CONTROL, VK_SPACE); // Ctrl + Space
SendMessage( HWND_BROADCAST,
WM_HOTKEY,
(WPARAM)hotkey , 0);
Am I on the right track? or this should be done completely in a different way?
SendInput is the best answer, honestly. This is because in the message loop your calls to the traslateaccellerator will look at the message , and in that message theres a bit flag on LPARAM, indicating what other keys are pressed with that key. You dont want to have to fill out that bit flag yourself, but ….. just in case you do .. and dont want to use SendInput…http://msdn.microsoft.com/en-us/library/ms646280%28VS.85%29.aspx details how to do it. Of course, if you want to use an AcceleratorTable, thats easily done with a resource editor, just in your message loop, hook it up with this http://msdn.microsoft.com/en-us/library/ms646373%28VS.85%29.aspx