CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Trouble getting program to recieve simulated xinput

  1. #1
    Join Date
    May 2020
    Posts
    3

    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.

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,357

    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?

  3. #3
    Join Date
    May 2020
    Posts
    3

    Re: Trouble getting program to recieve simulated xinput

    Quote Originally Posted by Arjay View Post
    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)