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

Thread: Xinput controller state problem

  1. #1
    Join Date
    Jun 2013
    Posts
    20

    Xinput controller state problem

    I am making a mapper program for the 360 controller using XInput I am using SendInput to send keypresses to games

    Code:
    if(controller1->GetState().Gamepad.wButtons & XINPUT_GAMEPAD_B)
    {
    			
    				
    	memset(&ip,0,sizeof(INPUT));//
                  UINT_PTR code = controller1->profile->Buttons[21]->keycode;
    	ip.type = INPUT_KEYBOARD;
    	ip.ki.wScan = MapVirtualKey(code,0);
    	ip.ki.time = 0;
    	ip.ki.dwExtraInfo = GetMessageExtraInfo();
    	ip.ki.wVk = 0;
    	ip.ki.dwFlags = KEYEVENTF_SCANCODE ;
    				
                  if(controller1->profile->Buttons[21]->delayTimer <= 0)
    	SendInput(1, &ip, sizeof(INPUT));
    
    	++controller1->profile->Buttons[21]->delayTimer;
    
    	if(controller1->profile->Buttons[21]->delayTimer >= 300)
    	{
    
    	++controller1->profile->Buttons[21]->repeatTimer;
    
    	if(controller1->profile->Buttons[21]->repeatTimer >= 100)
    	{
    
    						
    	SendInput(1, &ip, sizeof(INPUT));
    	 controller1->profile->Buttons[21]->repeatTimer = 0;
    				
    
    	}
    				
    	}
    				
    	}
    	else 
    	{
    				
    	ip.ki.dwFlags = KEYEVENTF_SCANCODE | KEYEVENTF_KEYUP ;
    	SendInput(1, &ip, sizeof(INPUT));
    	controller1->profile->Buttons[21]->delayTimer = 0;
    	controller1->profile->Buttons[21]->repeatTimer = 0;
    	
    	}
    it sends the key up event continuously wich is not what I want I want to make it so when the button is up it only send the key up event once. I figured I would do this using a current controller state and a previous controller state using an XOR but I have failed every attempt. Any advice would be helpful considering this is the only thing holding me back from finishing.

    P.S the code for checking the buttons state is in the main message loop.

  2. #2
    Join Date
    May 2020
    Posts
    3

    Re: Xinput controller state problem

    quick question, what are you using for your key codes?

  3. #3
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,797

    Re: Xinput controller state problem

    I doubt william3711 will read your question. His latest post to this forum was about seven years ago.
    Victor Nijegorodov

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)