WIN32 and XINPUT

Started by
1 comment, last by Mach5Mach 15 years, 5 months ago
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);
}

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);		}	}}
Nevermind, I fixed the problem. The way I was checking it lead to an incorrect conclusion.

This topic is closed to new replies.

Advertisement