Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

kevlur

How to get mouse click data with C++/DX9?

This topic is 5283 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 was thinking, how to get mouse-button state pressed/released with C++/DX9 ? ...to have something like this:

GetMouseButtonState(&Flag);

if(Flag & LEFT_BUTT_PRESSED)
{
 
}

if(Flag & LEFT_BUT_RELEASED)
{

}
thanks

Share this post


Link to post
Share on other sites
Advertisement
I can''t give you code but to get mouse data (and data from any input device) in DX9 you''ll have to use DirectInput. Take a look at MSDN here for more info on it.

Share this post


Link to post
Share on other sites
If you want to use DirectX for getting the mouse state you''d have to use DirectInput. This will get you access to all kinds of control devices, and also the mouse.

You can also still use the standard Win32-API calls for getting data from the default system mouse.
GetCursorPos for (screen) position and GetAsyncKeyState for the pressed buttons.

Share this post


Link to post
Share on other sites
Ok, i have to use GetAsyncKeyState(), but where can i find the list of the value for the logical AND with the return value of the function?
For example:


if(GetAsyncKeyState(VK_LBUTTON) & 0x8000)
{
// it means that the left mouse button is pressed, isn''t?

}

but how can i determine when the button is released? which is the value for logical AND for the release state?

thanks

Share this post


Link to post
Share on other sites
I think it''s not enought adding the else statement, because i dont need to know in which of 2 states(pressed/not pressed) is the mouse button, but i have to know in which
of 3 states(pressed/released/not pressed), i need to know when the button is released for the drag process.

How to determine when the button mouse is released?
(that''s different from knowing when the button is not pressed)

thanks

Share this post


Link to post
Share on other sites


BOOL g_bButtonPressed = FALSE;

...

if(GetAsyncKeyState(VK_LBUTTON) & 0x8000)
{
if(!g_bButtonPressed)
{
// do stuff you want to do when you first see it is pressed, like highlighting a drag item
g_bButtonPressed = TRUE;
}
else
{
// do stuff you want to do while the button is pressed, like dragging an item around
}
}
else
{
if(g_bButtonPressed)
{
// button has been released. Do release stuff
g_bButtonPressed = FALSE;
}
}

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!