Archived

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

Reading the Absolute Mouse Position

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

I have read a GD article I found about mouse input with DirectInput and it worked great. However the only snag is that the mouse position is only given in relative to the last time you updated the mouse position. It would be far more useful for me to know the absolute position of the cursor hotspot in pixels. Eg. DarkBasic''s MOUSEPOSITIONX() and MOUSEPOSITIONY() functions. Is there an answer within DirectInput or must I use the API instead? >>>>>>>>>>>>>>>>> Ilthigore <<<<<<<<<<<<<<<<<

Share this post


Link to post
Share on other sites
tweak it, change it by yourself. good thing, it''s still in pixel format, not some kind of freakin mouse coordinate.

this is what I do:

POINT mousepos;
mousepos.x = 0; // just an initial position
mousepos.y = 0;

mousepos.x += mousedata.lX;
mousepos.y += mousedata.lY;

if (mousepos.x < 0) mousepos.x = 0;
if (mousepos.x > 639) mousepos.x = 639;
// assuming it''s 640x480 resolution
// and do the same with y coordinate

not hard to do.


My compiler generates one error message: "does not compile."

Share this post


Link to post
Share on other sites
Thanks mate, that worked fine!!! However I now have another problem (sigh, one thing leads to another). I can get the absolute mouse input but I need to get the exact size and top left corner position of my window (when in windowed mode). If I cannot do this I will have to restrict it to fullscreen which would be a bit of a blow. I am currently experimenting with lParam of WM_MOVE, and WM_SIZE but could anyone tell me the way to use them (experimenting doesn''t always turn out the right way).

Share this post


Link to post
Share on other sites
there is an API to get your window position, is it GetWindowPos()? I forget. If it's windowed app, I suggest to use WinAPI instead. Much easier. Beware of the weirdness of screen and client coordinates (this is your problem). I did this once, but I don't really remember how.

I'm sure you need one call to get the mouse position relative to the screen. And then, call another function to convert it to client coordinate (which is coordinate relative to your window).


My compiler generates one error message: "does not compile."

[edited by - alnite on November 21, 2002 3:14:25 PM]

Share this post


Link to post
Share on other sites
My experimenting with lParam worked. I found out that in WM_MOVE:

LOWORD(lParam) == TopLeftCornerPositionX
HIWORD(lParam) == TopLeftCornerPositionY

Similarly in WM_SIZE:

LOWORD(lParam) == WidthOfWindow
HIWORD(lParam) == HeightOfWindow

Thanks for the advice anyway, maybe I shouldn''t have bothered posting about that one but oh well, thanks anyway.

>>>>>>>>>>>>>>>>>
Ilthigore
<<<<<<<<<<<<<<<<<

Share this post


Link to post
Share on other sites