Jump to content

MouseMove/MouseGetPos multiple monitors bug


bootybay
 Share

Recommended Posts

I found a topic about this from 2006. But since I don't want to necro it and it didn't solve my problem, I'll ask here for help.

I'd like to move the mousecursor by 1px with ctrl + arrowkeys. This works fine as long as the mouse is on the main monitor.

When I move the mouse to the left monitor it starts to get funky.

When I try to move left it wont work. When I move up it goes one up and one right. Moving right it will move 2px to the right.

Here is the script:

Opt("PixelCoordMode", 2)
Opt("MouseCoordMode", 2)

HotKeySet("^{UP}", "mmUP")
HotKeySet("^{DOWN}", "mmDOWN")
HotKeySet("^{LEFT}", "mmLEFT")
HotKeySet("^{RIGHT}", "mmRIGHT")

Func mmUP()
    MouseMove(MouseGetPos(0), MouseGetPos(1) - 1, 0)
EndFunc   ;==>mmUP

Func mmDOWN()
    MouseMove(MouseGetPos(0), MouseGetPos(1) + 1, 0)
EndFunc   ;==>mmDOWN

Func mmLEFT()
    MouseMove(MouseGetPos(0) - 1, MouseGetPos(1), 0)
EndFunc   ;==>mmLEFT

Func mmRIGHT()
    MouseMove(MouseGetPos(0) + 1, MouseGetPos(1), 0)
EndFunc   ;==>mmRIGHT

While 1
    Sleep(1000)
WEnd

Looks like jpm didn't fix it in 2006 :<

Link to comment
Share on other sites

I reproduced. How strange. Also:

  • It doesn't matter what Pixel/Mouse Coord Mode is chosen.
  • Three-monitor setup: the same thing happens on my left and on my right monitor. (Edit: both place the mouse 1 pixel too far to the right.) Thing is fine on my central (and main) monitor, works like a charm.
  • If I check the AutoIt Window Info tool, I see that the coordinates on the left monitor are negative, but that isn't the thing apparently, given point 2 (it also fails on right monitor, with positive x-coords). But if I get the MouseGetPos coordinates, I get positive numbers counted from the upper left of the left monitor.
  • After MouseMove(50,50,1); MouseGetPos(0) x MouseGetPos(1) gives me 51,50
Strange bug...
Edited by SadBunny

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

Works for me on both monitors...add some logging to see what's up:

Opt("PixelCoordMode", 2)
Opt("MouseCoordMode", 2)

HotKeySet("^{UP}", "mmUP")
HotKeySet("^{DOWN}", "mmDOWN")
HotKeySet("^{LEFT}", "mmLEFT")
HotKeySet("^{RIGHT}", "mmRIGHT")

Func mmUP()
    $x = MouseGetPos(0)
    $y = MouseGetPos(1)
    ConsoleWrite("move UP from [" & $x & "," & $y & "] to [" & $x & "," & $y-1 & "]." & @CRLF)
    MouseMove($x,$y-1, 0)
EndFunc   ;==>mmUP

Func mmDOWN()
    $x = MouseGetPos(0)
    $y = MouseGetPos(1)
    ConsoleWrite("move DOWN from [" & $x & "," & $y & "] to [" & $x & "," & $y+1 & "]." & @CRLF)
    MouseMove($x,$y+1, 0)
EndFunc   ;==>mmDOWN

Func mmLEFT()
    $x = MouseGetPos(0)
    $y = MouseGetPos(1)
    ConsoleWrite("move LEFT from [" & $x & "," & $y & "] to [" & $x-1 & "," & $y & "]." & @CRLF)
    MouseMove($x-1, $y, 0)
EndFunc   ;==>mmLEFT

Func mmRIGHT()
    $x = MouseGetPos(0)
    $y = MouseGetPos(1)
    ConsoleWrite("move RIGHT from [" & $x & "," & $y & "] to [" & $x+1 & "," & $y & "]." & @CRLF)
    MouseMove($x+1, $y, 0)
EndFunc   ;==>mmRIGHT

While 1
    Sleep(1000)
WEnd

right monitor:

move UP from [321,399] to [321,398].
move LEFT from [321,398] to [320,398].
move RIGHT from [320,398] to [321,398].
move DOWN from [321,398] to [321,399].

left monitor:

move UP from [-744,390] to [-744,389].
move DOWN from [-744,389] to [-744,390].
move LEFT from [-744,390] to [-745,390].
move RIGHT from [-745,390] to [-744,390].

Moving up decreases the $y coord since 0,0 is the top left of the monitor

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

Tried at work, W7 64 bits, dual monitor (at home: 8.1, triple monitor). Can only reproduce if/when I set my right screen as the main display:

MouseMove(-1000,50,1)
for $i = 1 to 10
    $x = MouseGetPos(0)
    $y = MouseGetPos(1)
    ConsoleWrite("Current x,y: " & $x & "," & $y & @CRLF)
    MouseMove($x, $y)
Next

This code should move mouse to -1000,50, then get the current pos which should be -1000,50, then move the mouse to that current position.

This is the console output:

Current x,y: -999,50
Current x,y: -998,50
Current x,y: -997,50
Current x,y: -996,50
Current x,y: -995,50
Current x,y: -994,50
Current x,y: -993,50
Current x,y: -992,50
Current x,y: -991,50
Current x,y: -990,50

If I set my left monitor to be the main display and go from 1000,50, it just stays at 1000,50 ten times like it should.

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

Similiar to SadBunnys log, my log also shows that MousGetPos(0) returns a value off by 1 on the the second monitor.

Mouse on the left (secondary) screen with desktop as the active window:

move LEFT from [1476,527] to [1475,527].
move LEFT from [1476,527] to [1475,527].
move UP from [1476,527] to [1476,526].
move UP from [1477,526] to [1477,525].
move RIGHT from [1478,525] to [1479,525].
move RIGHT from [1480,525] to [1481,525].
move DOWN from [1482,525] to [1482,526].
move DOWN from [1483,526] to [1483,527].

Mouse on the right (primary) screen with desktop as the active window:

move LEFT from [2459,178] to [2458,178].
move LEFT from [2458,178] to [2457,178].
move UP from [2457,178] to [2457,177].
move UP from [2457,177] to [2457,176].
move RIGHT from [2457,176] to [2458,176].
move RIGHT from [2458,176] to [2459,176].
move DOWN from [2459,176] to [2459,177].
move DOWN from [2459,177] to [2459,178].

I'm running Windows 7 Professional N with best performance settings.

AutoIt version used is v3.3.12.0

May I ask what your environment looks like jdelaney?

Link to comment
Share on other sites

  • 2 months later...

I found a topic about this from 2006. But since I don't want to necro it and it didn't solve my problem, I'll ask here for help.

...

Looks like jpm didn't fix it in 2006 :<

​And it looks like nobody has fixed yet... I've also found that topic from 2006 and then I got here. How it's possible that a bug still unsolved for almost 10 years? 

While that miracle happens I've solved the problem by myself using this simple piece of code:

Func myMouseMove($x,$y,$speed=0)
    if $x<0 Then $x-=1
    if $y<0 Then $y-=1
    MouseMove($x,$y,$speed)
EndFunc

It's very simple. When you move the cursor to a pixel position which is negative, the MouseMove() function performs the movement with an offset of +1px. That's why this only happens when you move the mouse on a screen above or on the left of the main screen. So you only have to substract 1px if you want to move the cursor to a negative pixel.

Link to comment
Share on other sites

It's probably not fixed because it's a low priority issue. I'm guessing not many people need single pixel precision on a mouse move.

EDIT: I also checked, and no one has ever put in a bug report on it that I can find, so it's even less of a priority without that.

Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • 7 years later...

For fellow Googlers still stumbling on this, here is a workaround that worked for me:

Func myMouseMove2($x,$y)
    DllCall("user32.dll ","bool","SetCursorPos","int",$x,"int",$y)
EndFunc
  • Tested on a dual monitor setup and works as intended on both screens.
  • Well, it does not handle speed but for single pixel precision moves, I don't think this would matter that much.
    If someone still feels this is required, take a hint here: in the Win32 API, the cursor move speed somehow has to be computed virtually.

Credits: https://www.autohotkey.com/boards/viewtopic.php?t=97706

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...