Jump to content
  • Advertisement
Sign in to follow this  
xtheendx

Question using DirectInput8 for mouse button

This topic is 3348 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, Basically I am using DirectInput8 in a game i am programming using direct3d. Everything is working fine, but there is something I would like to make work but can't figure out. Right now when you click a sprite with the mouse, then the sprite dies. This is how it should work, but if you just hold down mouse botton and move mouse around screen, it will kill anything it touches. If there anyway to stop this from happening, I want to have to click and reclick to kill the sprites, not just hold down mouse button and go crazy. Just general ideas would be good, if anyone else has encountered problem. thanks

Share this post


Link to post
Share on other sites
Advertisement
I'm afraid I can't help you specifically without seeing more code to see what's wrong. However, Microsoft recommend that you do not use DirectInput for keyboard and mouse input, but to use standard window messages instead.

Share this post


Link to post
Share on other sites
Looks like you will need to store the previous mouse input data.
So whenever you reload the input data (you should do it once before every game update), you'll need to copy the current input data to the previous input data memory location before you read the new mouse state.
And when you'll need to get the button state, you can return 0 if it isn't pressed for 2 ticks (the time in which a frame is processed), 1 if it was pressed now, 2 when it was held for 2 ticks and 3 if it is released.
Like this (pseudocode):
if( state_prev.buttons[ button_id ] == false )
{
if( state_curr.buttons[ button_id ] == false )
{
return 0;
}
else
{
return 1;
}
}
else
{
if( state_curr.buttons[ button_id ] == true )
{
return 2;
}
else
{
return 3;
}
}


You can even transfer the button states to the keyboard states and add the DIK_LMOUSE, DIK_RMOUSE, DIK_MMOUSE(, DIK_MOUSE3?), DIK_MWHEELUP, DIK_MWHEELDN "keys" like I did. It makes input reading a lot easier when you are only developing the control scheme.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!