PRB: mouse_event and Absolute Moves on Secondary Monitors

ID: Q193003

The information in this article applies to:

SYMPTOMS

When you use mouse_event with absolute positions on Windows 98, the mouse cursor only moves over the primary monitor. If you try to move the cursor onto a secondary monitor attached to the desktop, the cursor stops at the edge of the primary monitor. Relative mouse movements move the cursor to the primary or secondary monitor as appropriate. The behavior of moving the cursor over an area of the desktop that is not on any monitor is undefined.

CAUSE

This behavior is by design for backward compatibility with Windows 95.

RESOLUTION

In some cases, this behavior is not desired. You can use the following sample code to emulate absolute movement over the entire virtual desktop:

Sample Code

   // Visual C++ 5.0 does not define these constants. Visual C++ 6.0 does,
   // so you need to allow for both possibilities.

   #ifndef SPI_GETMOUSESPEED
   #define SPI_GETMOUSESPEED   112
   #endif

   #ifndef SPI_SETMOUSESPEED
   #define   SPI_SETMOUSESPEED   113
   #endif

      int oldAccel[3], newAccel[3], oldSpeed, newSpeed, x, y;
      BOOL bResult;

   // The following values set mouse ballistics to 1 mickey/pixel.
      newAccel[0] = 0;
      newAccel[1] = 0;
      newAccel[2] = 0;
      newSpeed = 1;

      // Save the Current Mouse Acceleration Constants
      bResult = SystemParametersInfo(SPI_GETMOUSE,0,oldAccel,0);
      bResult = SystemParametersInfo(SPI_GETMOUSESPEED, 0, &oldSpeed,0);
      // Set the new Mouse Acceleration Constants (Disabled).
      bResult =
   SystemParametersInfo(SPI_SETMOUSE,0,newAccel,SPIF_SENDCHANGE);
      bResult = SystemParametersInfo(SPI_SETMOUSESPEED, 0,
   &newSpeed,SPIF_SENDCHANGE);

      //Pick some arbitrary x & y values.
           x = -100;
           y = -150;

           mouse_event(MOUSEEVENTF_ABSOLUTE,0,0,0,0);
           // Move cursor to UL of primary monitor (origin).
           mouse_event(0,x,y,0,0);
           // Move the cursor to the desired coordinates.

      // Restore the old Mouse Acceleration Constants.
      bResult = SystemParametersInfo(SPI_SETMOUSE,0, oldAccel,
   SPIF_SENDCHANGE);
      bResult = SystemParametersInfo(SPI_SETMOUSESPEED, 0, &oldSpeed,
   SPIF_SENDCHANGE);

MORE INFORMATION

Windows NT allows absolute mouse moves onto any monitor that is part of the desktop.

Additional query words:

Keywords          : kbInput kbMouse kbSDKPlatform kbWinOS98 kbCodeSam kbfaq
Issue type        : kbprb

Last Reviewed: September 27, 1998