Jump to content
  • Advertisement
Sign in to follow this  
blueshogun96

Windows Mouse Handling Sucks

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

In my opinion, of course...

My game not only needs to know if the mouse is currently out of the game's window, but also the position of the cursor relative to the window as it moves outside.  MacOS and Linux give me this by default, but for Windows, I had quite a bit of trouble finding a reliable way to do it.  This isn't the first time I've had issues dealing with Window's mousing handling.  It's been a pain in my arse multiple projects.

 

#if defined(_WIN32) && !defined(_WINRT)
	/* Because Windows mouse handling sucks in general compared to Mac/Linux, a little extra
	   work is required to find out if the cursor is outside of the game's window to prevent
	   cheating.  In my experience, the reliability of GetCursorPos and ScreenToClient vary
	   from one comp/OS to another, so a better idea is to check every frame and use those
	   resulting coordinates only if it tells us we are off screen.  No disrespect Microsoft,
	   but why do you insist on making such trivial things a pain in my behind sometimes? */

	struct vec2_t<float> bounds;

	This->get_bounds( bounds );

	POINT pt;
	GetCursorPos((POINT*)&pt);
	ScreenToClient(GetActiveWindow(), (POINT*)&pt);

	if( pt.x < 0 || pt.x > bounds.v[0] || pt.y < 0 || pt.y > bounds.v[1] )
	{
		This->mouse_move_func(pt.x, pt.y);
	}
#endif

 

So yeah, I can't believe it took me that long to get this stupid thing figured out.  Anyone else have the same problem before?  Anyone else come up with a better solution?  I'm just glad it works....

Shogun

Share this post


Link to post
Share on other sites
Advertisement
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!