I’m trying to send a ALT-S to a dialog prompt for saving a file using PostMessage :
PostMessage(h, WM_KEYDOWN, VK_MENU, 0);
PostMessage(h, WM_KEYDOWN, ord('S'), 0);
PostMessage(h, WM_KEYUP, ord('S'), 0);
PostMessage(h, WM_KEYUP, VK_MENU, 0);
But it does not work. It sends the two keys, but it’s as if the ALT condition is not recognised by the dialog box, and handled as a normal S character.
I’ve done a LOT of reading, including this (which produces an error), it seems I need to do something in the lparam to indicate ALT is depressed. Some sources say 0x20000000 but this does not work either.
SendInput, keybd_event, etc will not work for me, since the dialog box will not be in focus.
I’m quite stumped would appreciate some insight.
By far the easiest way to press a button on another form is to send a
WM_COMMANDmessage rather than faking input. Faking input is a tricky business and can often fail to do what you desire.Send the
WM_COMMANDto the top level window. Pass notification codeBN_CLICKEDaswParamand the buttons ID aslParam.You can use
FindWindoworEnumWindowsto obtain the handle of the top-level window. A program like Spy++ would enable you to find out the ID of the target button.