robotgo icon indicating copy to clipboard operation
robotgo copied to clipboard

robotgo.Move moves cursor to invalid position on multi-monitor setup

Open SirRFI opened this issue 3 years ago • 6 comments

  • Robotgo version (or commit ref): v1.0.0-beta5
  • Go version: go version go1.17.6 windows/amd64
  • Gcc version: gcc.exe (x86_64-win32-seh-rev0, Built by MinGW-W64 project) 8.1.0 (recommended by README)
  • Operating system and bit: Windows 10 64bit
  • Resolution: 1920x1080 x3 - 3 monitors with same resolution, middle one set a primary/main
  • Provide example code:
package main

import (
	"fmt"
	"github.com/go-vgo/robotgo"
)

func main() {
	robotgo.Move(10, 100)
	robotgo.MilliSleep(1) // optional
	x, y := robotgo.GetMousePos()
	fmt.Println(x, y) // outputs -1910 99
}

Description

robotgo.Move moves cursor to absolute X, Y position that is passed to the function. robotgo.GetMousePos returns position of the cursor, which used immediately after robotgo.Move should be exactly the same, assuming no user input.

Since robotgo.Move moves cursor to invalid location since [email protected], at least on multi-monitor setup like my own - 3 monitors with 1920x1080 resolution, middle one being set as primary/main, therefore starting with X 0, Y 0, and the left one has negative X positions.

Same code tested with other versions:

go get github.com/go-vgo/[email protected] | go run .
10 100

go get github.com/go-vgo/[email protected] | go run .
-1910 99

go get github.com/go-vgo/[email protected] | go run .
-1910 99

Aside from X being affected, you can see that Y is off by one.

SirRFI avatar Feb 20 '22 13:02 SirRFI

I will check it.

vcaesar avatar Feb 20 '22 22:02 vcaesar

Fixed in beta5.1, and not support multi screen in Windows now.

vcaesar avatar Apr 08 '22 22:04 vcaesar

New test:

Setup:

Windows 11 (21H2, build 22000.556)
go version go1.18 windows/amd64
gcc.exe (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 8.1.0

Code:

package main

import (
	"github.com/go-vgo/robotgo"
	"fmt"
)

func main() {
	// Setup: 3 1920x1080 screens - middle one is primary
	moveTo(0, 0) // middle screen
	moveTo(10, 100) // middle screen
	moveTo(-1900, 100) // left screen
	moveTo(1930, 100) // right screen
}

func moveTo(x int, y int) {
	robotgo.Move(x, y)
	robotgo.MilliSleep(100)
	x, y = robotgo.GetMousePos()
	fmt.Println(x, y)
	robotgo.MilliSleep(900)
}

Result:

go get github.com/go-vgo/[email protected] | go run .
go: downgraded github.com/go-vgo/robotgo v1.0.0-beta5 => v0.100.10
0 0
10 100
-1900 100
1930 100

go get github.com/go-vgo/[email protected] | go run .
go: upgraded github.com/go-vgo/robotgo v0.100.10 => v1.0.0-beta3
-1920 0
-1910 99
-1920 99
9 99

go get github.com/go-vgo/[email protected] | go run .
go: upgraded github.com/go-vgo/robotgo v1.0.0-beta3 => v1.0.0-beta5
-1920 0
-1910 99
-1920 99
9 99

go get github.com/go-vgo/[email protected] | go run .
go: upgraded github.com/go-vgo/robotgo v1.0.0-beta5 => v1.0.0-beta5.1
-1920 0
-1891 99
-1920 99
-1 99

Well, something did change (-1891 vs -1920 and 9 vs -1 in X), but it's not fixed - values from robotgo.Move still don't match values from robotgo.GetMousePos(), be it outside main screen or not.

Side note: I have taskbar on the right monitor.

Windows considers anything to the left or up from primary screen to be in negative position. However, when image search is done, it takes a screenshot and returns position of found image within the screenshot, which cannot be negative. At least this is how I think it works as far I tested it all. Not directly related to the issue, but this is something to consider.

SirRFI avatar Apr 11 '22 15:04 SirRFI

meet with the same issue in multi-screen scene

ileon avatar Jun 22 '22 02:06 ileon

have any plan to support mutiscreen on windows and fix this?

mostcute avatar Feb 22 '23 09:02 mostcute