-
May 14th, 2020, 01:56 PM
#1
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.
-
May 18th, 2020, 12:29 AM
#2
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?
-
May 19th, 2020, 01:11 PM
#3
Re: Trouble getting program to recieve simulated xinput
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.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|