Sign in to follow this  
gooeycola

Problem with DirectInput Mouse Control

Recommended Posts

-------------------------------------------------------------------------------- Hi. I'm trying out following simple code which prints out the position of the mouse cursor when it's clicked. INT CGamePrepScreen::GetInput() { if ( m_LP_DIDevice_Mouse->GetDeviceState( sizeof( DIMOUSESTATE ) , ( LPVOID ) &m_Mouse_State ) != DI_OK ) { return ERR; } if ( m_LP_DIDevice_Mouse->GetDeviceState( sizeof( DIMOUSESTATE ) , ( LPVOID ) &m_Mouse_State ) == ( DIERR_INPUTLOST | DIERR_NOTACQUIRED ) ) { return m_LP_DIDevice_Mouse->Acquire(); } if ( m_Mouse_State.rgbButtons[0] & 0x80 ) { CHAR* testChar = new CHAR; RECT windowRect; POINT mousePoint; HRESULT ddrVal; GetWindowRect( m_Hnd_Parent_Window , &windowRect ); GetCursorPos( &m_Rel_Mouse_Position ); mousePoint.x = m_Rel_Mouse_Position.x - windowRect.left; mousePoint.y = m_Rel_Mouse_Position.y - windowRect.top; wsprintf( testChar, "Mouse x-coord is %d , Mouse y-coord is %d \n", mousePoint.x , mousePoint.y ); OutputDebugString( testChar ); } return 0; } And I call the function in the while loop like this: while (GetMessage(&msg, NULL, 0, 0)) { if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } g_Game_Prep_Screen->GetInput(); } But whenever I click the mouse button there's one problem that causing me a headache. To my understanding, if ( m_Mouse_State.rgbButtons[0] & 0x80 ){ .. } <- this if statement should return true only if the mouse button is clicked. Then it should return false on other conditions. But whenever I click the mouse button only once, it returns true and when it loops back, it returns true again. So it thinks that I clicked the button twice. any ideas why it occurs? Thank you in advance.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this