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);
}