• Advertisement
Sign in to follow this  

Problem with DirectInput Mouse Control

This topic is 4890 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

-------------------------------------------------------------------------------- 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
Advertisement
The button flag will be set as long as the button is actually pushed.

For one time clicks you need to maintain a hasbeenpressed or hasnotbeenreleased flag yourself.

Share this post


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

  • Advertisement