Quantcast
Channel: GameDev.net
Viewing all articles
Browse latest Browse all 17825

Windows Mouse Handling Sucks

$
0
0
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

Viewing all articles
Browse latest Browse all 17825

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>