Problem with SendInput function

Hello all. I'm trying to synthesize alt + space to bring up the output window's menu using SendInput(). For some reason it works on other windows that I click on after compiling, but CMD windows just take it as a space key press. Here's what I have:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
        Sleep(2500);

	INPUT in1 = {INPUT_KEYBOARD};
	INPUT in2 = {INPUT_KEYBOARD};
	INPUT in3 = {INPUT_KEYBOARD};
	INPUT in4 = {INPUT_KEYBOARD};
	KEYBDINPUT k1 = {VK_MENU,0,0,0,0};
	KEYBDINPUT k2 = {VK_SPACE,0,0,0,0};
	KEYBDINPUT k3 = {VK_SPACE,0,KEYEVENTF_KEYUP,0,0};
	KEYBDINPUT k4 = {VK_MENU,0,KEYEVENTF_KEYUP,0,0};
	in1.ki = k1;
	in2.ki = k2;
	in3.ki = k3;
	in4.ki = k4;
	SendInput(1, &in1, sizeof(INPUT));
	SendInput(1, &in2, sizeof(INPUT));
	SendInput(1, &in3, sizeof(INPUT));
	SendInput(1, &in4, sizeof(INPUT));

	system("pause");
Better use GetSystemMenu() instead.
Thanks for the response. It looks like GetSystemMenu() only modifies the menu; plus, I'd rather not download the MFC library. I just need to paste some data from the clipboard to the output window (I was trying to simulate alt + space, e, p for edit -> paste). Can't believe how much trouble such a simple task is giving me.. it looks like automated alt + space is disabled as a security measure or something.. can't find anything on the internet about it.
You don't need MFC, it is a plain windows API.
To insert text into a text window send WM_SETTEXT message to window handle.
Use OpenClipboard() and family to get/set the text in clipboard.
closed account (DSLq5Di1)
After a little fooling around I managed to get it working by sending the scan code with VK_SPACE, why that works? I have no idea..

1
2
3
4
5
6
7
8
INPUT alt_space[] =
{
        { INPUT_KEYBOARD, MAKELONG(VK_MENU, 0) },
        { INPUT_KEYBOARD, MAKELONG(VK_SPACE, MapVirtualKey(VK_SPACE, 0)) },
        { INPUT_KEYBOARD, MAKELONG(VK_SPACE, MapVirtualKey(VK_SPACE, 0)), KEYEVENTF_KEYUP },
        { INPUT_KEYBOARD, MAKELONG(VK_MENU, 0), KEYEVENTF_KEYUP }
};
SendInput(ARRAYSIZE(alt_space), alt_space, sizeof INPUT);
Woooooo it works thanks!!
Topic archived. No new replies allowed.