Jump to content
  • Advertisement
Sign in to follow this  
Mach5Mach

WIN32 and XINPUT

This topic is 3651 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to build a quick GUI that right now just consists of a window. I also want to use OpenGL in conjunction with this. I'm using XInput to grab input from the xbox 360 controller and WIN32 api to display the gui stuff. My problem lies in the fact that when I'm trying to get the GamePad state, it repeats until I press something else, or terminate the program. That is, it hangs on to the last input. Here's some of my code, any help is appreciated. inside my xbox360controller class:
XINPUT_STATE Xbox360Controller::GetInputState()
{
	uli4 uliResult;
	ZeroMemory( &m_pState, sizeof(XINPUT_STATE) );
	uliResult = XInputGetState(DWORD(m_usiControllerNumber), &m_pState);
	m_bIsConnected = uliResult == ERROR_SUCCESS;
	return m_pState;
}

my window class's update func:
void Window::Update()
{
	MSG			msg;		//Windows message structure
	msg.message = (~WM_QUIT);

	//process application messages until it closes
	while(msg.message != WM_QUIT)
	{
		if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
		{	
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}

		p_fUpdateFunc();	
	}
}

my window class's WndProc callback
LRESULT CALLBACK Window::WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	static PAINTSTRUCT ps;

    switch(msg)
    {
	case WM_ACTIVATEAPP:
		if(wParam == TRUE)
		{
			XInputEnable(true);
		}
		else
		{
			XInputEnable(false);
		}
		break;
	case WM_PAINT:
		BeginPaint(hWnd, &ps);
		p_fUpdateFunc();
		EndPaint(hWnd, &ps);
		break;
	case WM_LBUTTONDOWN:
		break;
	case WM_RBUTTONDOWN:
		break;
	case WM_CLOSE:
            DestroyWindow(hWnd);
		break;
    case WM_DESTROY:
            PostQuitMessage(0);
		break;
    }
   return DefWindowProc(hWnd, msg, wParam, lParam);
}

checking for button
b1	Xbox360Controller::GetAButton()
{
	return	((m_pState.Gamepad.wButtons	&	XINPUT_GAMEPAD_A)	!=	0);
}

Share this post


Link to post
Share on other sites
Advertisement
here's my update func that is called by the window
p_fUpdateFunc is a function pointer that is set to this procedure


void UpdateScene() //updated loop
{
tTimer->Start();
display();
tTimer->Stop();

fpscMain->Update();

imControllers->Update();

b1 repaint = false;
for(usi2 i = 0; i < imControllers->GetNumberOfControllers(); i++)
{
if(imControllers->GetController(i)->GetAButton())
{
repaint = true;
fprintf(file, "CONTROLLER[%d]: A pressed\n", i);
}
if(imControllers->GetController(i)->GetBButton())
{
repaint = true;
fprintf(file, "CONTROLLER[%d]: B pressed\n", i);
}
if(imControllers->GetController(i)->GetXButton())
{repaint = true;
fprintf(file, "CONTROLLER[%d]: X pressed\n", i);
}
if(imControllers->GetController(i)->GetYButton())
{repaint = true;
fprintf(file, "CONTROLLER[%d]: Y pressed\n", i);
}
if(imControllers->GetController(i)->GetLeftShoulderButton())
{repaint = true;
fprintf(file, "CONTROLLER[%d]: LB pressed\n", i);
}
if(imControllers->GetController(i)->GetRightShoulderButton())
{repaint = true;
fprintf(file, "CONTROLLER[%d]: RB pressed\n", i);
}
if(imControllers->GetController(i)->GetLeftThumbstickClick())
{repaint = true;
fprintf(file, "CONTROLLER[%d]: Left Thumbstick pressed\n", i);
}
if(imControllers->GetController(i)->GetRightThumbstickClick())
{repaint = true;
fprintf(file, "CONTROLLER[%d]: Right Thumbstick pressed\n", i);
}
if(imControllers->GetController(i)->GetStartButton())
{repaint = true;
fprintf(file, "CONTROLLER[%d]: Start pressed\n", i);
}
if(imControllers->GetController(i)->GetBackButton())
{repaint = true;
fprintf(file, "CONTROLLER[%d]: Back pressed\n", i);
}
if(imControllers->GetController(i)->GetLeftThumbstickClick())
{repaint = true;
fprintf(file, "CONTROLLER[%d]: Left Thumbstick pressed\n", i);
}
if(imControllers->GetController(i)->GetRightThumbstickClick())
{repaint = true;
fprintf(file, "CONTROLLER[%d]: Right Thumbstick pressed\n", i);
}
}
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!