Search code examples
c++windowswinapisendinput

SendInput wrong Parameter


I wanted to improve my SendInput() function but came across an error.

ERROR_INVALID_PARAMETER

87 (0x57)

The parameter is incorrect.

https://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85).aspx

I am a bit confused which parameter should not be correct.

If I have forgotten something do not hesitate to ask.

INPUT in[6] = {0};

//Press Enter Key
in[0].type = INPUT_KEYBOARD;
in[0].ki.wScan = 0;
in[0].ki.dwFlags = 0;
in[0].ki.time = 0;
in[0].ki.dwExtraInfo = 0;
in[0].ki.wVk = VK_RETURN;

//release enter key
in[1] = in[0];
in[1].ki.dwFlags = KEYEVENTF_KEYUP;

//Hold Shift key and press key 7
in[2].type = INPUT_KEYBOARD;
in[2].ki.wScan = 0;
in[2].ki.dwFlags = 0;
in[2].ki.time = 0;
in[2].ki.dwExtraInfo = 0;
in[2].ki.wVk = VK_SHIFT;

in[3].type = INPUT_KEYBOARD;
in[3].ki.wScan = 0;
in[3].ki.dwFlags = 0;
in[3].ki.time = 0;
in[3].ki.dwExtraInfo = 0;
in[3].ki.wVk = 0x37;

//release key 7
in[4] = in[3];
in[4].ki.dwFlags = KEYEVENTF_KEYUP;

//release key shift
in[5] = in[2];
in[5].ki.dwFlags = KEYEVENTF_KEYUP;

if (SendInput(6, in, sizeof(in)) == 0)
{
std::cout << "Uppps some error in SendInput: " << GetLastError() << std::endl;
}

Solution

  • The size, in bytes, of an INPUT structure. If cbSize is not the size of an INPUT structure, the function fails.

    SendInput(6, in, sizeof(INPUT));
    

    Oups...