# IDirectInput - Absolute coords mishap?

This topic is 3381 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, [* Please forgive me for the long post *] I don't wish to make this complicated, but I promise all my tests show that the following variables are not good for computing absolute screen coordinates: dims2.lX (or .lY for vertical movement), I have read many threads on this and all keep saying that they use it for correct absolute coords computation, but I am failing to see how it can possibly work.. Here is my setup: - mouse.cpp (VC8 sln from DirectX SDK) - select NONEXCL, FOREGROUND, IMMEDIATE (mouse format is c_dfDIMouse2) In the code, try this:
...
int absx=-777;
INT_PTR CALLBACK MainDlgProc( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam )
{
...
POINT pt;
pt.x = 0;
pt.y = 0;
ClientToScreen(hDlg, &pt);
SetCursorPos(pt.x, pt.y);
absx = pt.x;
if( FAILED( OnCreateDevice( hDlg ) ) )
...


And replace the following lines:
// The dims structure now has the state of the mouse, so
// display mouse coordinates (x, y, z) and buttons.
//StringCchPrintf( strNewText, 128, TEXT("(X=% 3.3d, Y=% 3.3d, Z=% 3.3d) B0=%c B1=%c B2=%c B3=%c B4=%c B5=%c B6=%c B7=%c"),
//                     dims2.lX, dims2.lY, dims2.lZ,
//                    (dims2.rgbButtons[0] & 0x80) ? '1' : '0',
...


With:
// The dims structure now has the state of the mouse, so
// display mouse coordinates (x, y, z) and buttons.
absx = absx + dims2.lX;
StringCchPrintf( strNewText, 128, TEXT("#%d#"), absx);


When you compile and run it you will see that you will never get back to the original absolute screen coord where the mouse starts at 358). Can someone try it and let me know if I AM doing anything wrong ?... (In this sample, I am logging the X coordinate) dims2.lX is a mickey value, we know that, maybe this should be first converted to a pixel coord value before it is added? If so, what's the proper way to this conversion ? Many thanks and sorry for the long post

##### Share on other sites
Going a little off topic, but Using DirectInput for keyboard or mouse input is a terrible idea and will just cause you headaches (Like this), and break your app on some machines (Although that's more a keyboard thing rather than a mouse thing).

Back on topic; You can't get absolute mouse coordinates in any way that I'm aware of - DirectInput doesn't work with pixels, it works in mickeys, so it has no concept of where "zero" is.

##### Share on other sites
Ah Steve! How could I say thanks!...

I'm glad to see that I wasn't wrong ;-)

Thanks for the other links... it could have saved me from some irritable threads.

Cheers.