Trouble getting program to recieve simulated xinput
I have been writing a program which needs to simulate an input from a controller. I have been using SendInput() with a keyboard input and used VK_GAMEPAD_A as my test key.
Code:
void PressButton(WORD key, unsigned short time = 50)
{
INPUT Input = { 0 };
unsigned int size = sizeof(INPUT);
WORD vKey = MapVirtualKey(key, 0);
Input.type = INPUT_KEYBOARD;
Input.ki.wScan = vKey;
Input.ki.dwExtraInfo = GetMessageExtraInfo();
Input.ki.dwFlags = KEYEVENTF_SCANCODE;
SendInput(1, &Input, size);
Sleep(100);
ZeroMemory(&Input, size);
Input.type = INPUT_KEYBOARD;
Input.ki.wScan = vKey;
Input.ki.dwExtraInfo = GetMessageExtraInfo();
Input.ki.dwFlags = KEYEVENTF_SCANCODE;
SendInput(1, &Input, size);
Sleep(time);
}
When I run this code nothing happens. Is this a problem with my code or with the receiving program? Am I using the right keycode?
Also I will need to do joysticks and triggers. There will be a float or double as the input for those.
Re: Trouble getting program to recieve simulated xinput
SendInput requires that the receiving window has focus. Are you able to send a regular key (say an, 'A') to a window like notepad?
Re: Trouble getting program to recieve simulated xinput
Quote:
Originally Posted by
Arjay
SendInput requires that the receiving window has focus. Are you able to send a regular key (say an, 'A') to a window like notepad?
Yes, I am able to send mouse and keyboard input. I noticed that I didn't include KEYEVENTF_KEYUP to the dwFlags list, however this didn't fix the issue.