2

I can't test different Windows versions, but I suspect it's a Windows 8 issue (due to the corner and side hotspots).

I'm trying to move the cursor to specified coordinates using SendInput, SetCursorPos, mouse_event and MoveMouse from Autohotkey and AutoIt. It works when moving the cursor on the same monitor, but not when crossing monitors.

When crossing monitors, if my mouse cursor is at (100, 100) on secondary monitor (to the right), moving to (0, 0) (primary monitor) will move and stay there. GetCursorPos will tell me it's at (0, 0). But soon as I move, the cursor starts from (0, 0) on secondary monitor.

How do I move my cursor across my monitor without having it jump to the original monitor again?

SendInput example C++:

int MouseMove(int x, int y) {
    int screenWidth = GetSystemMetrics(SM_CXVIRTUALSCREEN);
    int screenHeight = GetSystemMetrics(SM_CYVIRTUALSCREEN);

    INPUT input;
    input.type = INPUT_MOUSE;
    input.mi.dx = round((x * 65535) / (screenWidth - 1));
    input.mi.dy = round((x * 65535) / (screenHeight - 1));
    input.mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_VIRTUALDESK | MOUSEEVENTF_MOVE;
    input.mi.mouseData = 0;
    input.mi.time = 0;
    input.mi.dwExtraInfo = 0;

    return SendInput(1, &input, sizeof(INPUT));
}

AutoHotkey example:

CoordMode, Mouse, Screen
MouseMove, 0, 0, 0

AutoIt example:

MouseMove(0, 0, 0)
user4157124
  • 2,809
  • 13
  • 27
  • 42
Nathan
  • 56
  • 5
  • Not sure if its correct, but if you have two monitors of eg. 1024 width, your resolution is 2048. So moving it to 0,0 is indeed the first display. Do a mouse move to (1024,0) if you want to be at the top left of the second monitor. – Milos Jun 10 '15 at 12:50
  • @Milos Right, but when I move to (0, 0), from the secondary monitor, after moving the cursor over a pixel, the mouse will jump to (1024, 0), as if it was there the whole time, even though it really did move to (0, 0), and could even click from there. – Nathan Jun 10 '15 at 23:31
  • raw input coordinates are normalized device coordinates, getcursorpos, setcursorpos, are virtual desktop coordinates. They are not the same thing. Whoever gave this too you gave you incorrect equation: round((x * 65535) / (screenWidth - 1)); You need to replace it with the correct one. – Dan May 02 '19 at 16:43

2 Answers2

0

I have no way of testing your issue but maybe I can point you in the right direction.

The only thing I can think of is using MouseGetPos to store your current mouse position,SysGet to grab the 2nd Monitor, and use MouseMove to return you to original position after your SendInput.

Hope this helps.

errorseven
  • 2,672
  • 2
  • 14
  • 20
  • I might have made my question a bit unclear, since I slapped the actual question in between a bunch of other stuff, but I'm trying to get my mouse not to move back to its original location. Currently, if it crosses to a new monitor, it will return to the old monitor once moved. I'd like for it to stay where it was, such as when the cursor moves from one point to another on the same monitor. – Nathan Jun 10 '15 at 00:37
0

This may be a bug in Autoit or Windows.

Try doing MouseMove in a different way and play with $Window.

Local $WM_MOUSEMOVE     =  0x0200

DllCall("user32.dll", "int", "SendMessage", _
        "hwnd",  WinGetHandle( $Window ), _
        "int",   $WM_MOUSEMOVE, _
        "int",   0, _
        "long",  _MakeLong($X, $Y))

Are your monitors set to Extend mode?

Milos
  • 2,927
  • 1
  • 15
  • 27