I want to send Alt + Mouse Click to some programs.
It works in most programs, it needs a small delay for some, but doesn't work at all in one of them.
The mouse click is working, but the Alt key isn't. If I hold Alt manually and trigger a Mouse Click with SendInput()
, it works. So I assume that the Alt key press is not being sent/handled correctly?
This is the code I'm using:
void SendAltClick()
{
INPUT inputs[4] = {};
ZeroMemory(&inputs, sizeof(INPUT));
// Alt down
inputs[0].type = INPUT_KEYBOARD;
inputs[0].ki.wVk = VK_MENU;
// Left down
inputs[1].type = INPUT_MOUSE;
inputs[1].mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
// Left up
inputs[2].type = INPUT_MOUSE;
inputs[2].mi.dwFlags = MOUSEEVENTF_LEFTUP;
// Alt up
inputs[3].type = INPUT_KEYBOARD;
inputs[3].ki.wVk = VK_MENU;
inputs[3].ki.dwFlags = KEYEVENTF_KEYUP;
SendInput(ARRAYSIZE(inputs), inputs, sizeof(INPUT));
}
All calls to SendInput()
return 1.
I've also tried Ctrl/Shift + Click, and they work as expected.
Why doesn't it behave the same way with all programs? Why does it need a small delay for some of them? Why doesn't it work at all with one of them?
I can only reproduce with some specific programs. I don't know if I should post the specific details here, since they contain names to commercial products.
EDIT: I went back to the documentation and found the following note at the end of the remarks section, could it be related? How?
An accessibility application can use SendInput to inject keystrokes corresponding to application launch shortcut keys that are handled by the shell. This functionality is not guaranteed to work for other types of applications.