0

I'm trying to alter the mouse-coordinates returned by the touch-screen. For example, if I have an app that is always full-screen, and the user touches coordinate (1023, 767), then I want the mouse cursor to be at (799, 479). It should be a simple scaling formula, but I can't seem to achieve that. I've tried changing the coordinates in PreTranslateMessage, but it doesn't seem to have any effect, no matter what I set the values to.

I need to do this at the application level, because I don't have access to the driver/controller level.

Here's a sample of my experiment:

BOOL CMyDialog::PreTranslateMessage(MSG* pMsg)
{
   if (pMsg->message == WM_LBUTTONDOWN ||
       pMsg->message == WM_LBUTTONUP ||
       pMsg->message == WM_MOUSEMOVE)
   {
      // In this example, I'm simply reducing the "screen" by half.
      // I am expecting that the mouse cursor would always be between
      // my touch point and the upper-left corner, with a distance of half.
      // But nothing seems to be happening. Is pMsg->pt just "read-only"?

      pMsg->pt.x = pMsg->pt.x / 2;
      pMsg->pt.y = pMsg->pt.y / 2;
   }

   return CDialog::PreTranslateMessage(pMsg);
}
Ryuu
  • 779
  • 11
  • 22

1 Answers1

1

I'm certain your OnLButtonDown handler does indeed get the modified values of your coordinates. The mouse message has nothing to do wit the 'physical' location of your mouse. It's merely a message telling your window that a mouse event occurred at a certain position.

To set the actual position of the mouse, you need to call SetCursorPos. Also, I believe you should handle the WM_TOUCH message.

Edit: If you want to catch mouse coordinates globally in your application, then consider using a hook. SetWindowsHookEx + WH_MOUSE. This can be done from another process, but in that case you need to put the hooking stuff in a DLL, which the OS will inject for all processes (see this). One thing to remember; always make your hooks as lightweight as possible!

Community
  • 1
  • 1
l33t
  • 18,692
  • 16
  • 103
  • 180
  • I tested it, and the `OnLButtonDown` received the unaltered coordinate, so what I did in `PreTranslateMessage` has no effect. Unfortunately I don't have much experience in Windows programming. I'm assuming this can only be done at the driver level? – Ryuu Nov 20 '12 at 10:20
  • You can always perform the calculations in the handlers. E.g. OnLButtonDown(...). Why not do that? – l33t Nov 21 '12 at 20:43
  • It will not work across multiple dialogs within an application, because the wrong dialog's OnLButtonDown will be called. The translation needs to be done earlier or at a lower level. I wonder if it is possible to create another app that always "steals" the mouse input and retranslates it, before my original app ever got the message. – Ryuu Nov 25 '12 at 08:35