Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
SirRFI opened this issue Feb 20, 2022 · 6 comments
Open

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

SirRFI opened this issue Feb 20, 2022 · 6 comments
Labels
Milestone

Comments

@SirRFI
Copy link

SirRFI commented Feb 20, 2022

  • 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 robotgo@v1.0.0-beta1, 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/robotgo@v0.100.10 | go run .
10 100

go get github.com/go-vgo/robotgo@v1.0.0-beta1 | go run .
-1910 99

go get github.com/go-vgo/robotgo@v1.0.0-beta3 | go run .
-1910 99

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

@vcaesar vcaesar added this to the v1.0.0 milestone Feb 20, 2022
@vcaesar
Copy link
Member

vcaesar commented Feb 20, 2022

I will check it.

@vcaesar
Copy link
Member

vcaesar commented Apr 8, 2022

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

@SirRFI
Copy link
Author

SirRFI commented Apr 11, 2022

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/robotgo@v0.100.10 | 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/robotgo@v1.0.0-beta3 | 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/robotgo@v1.0.0-beta5 | 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/robotgo@v1.0.0-beta5.1 | 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.

@ileon
Copy link

ileon commented Jun 22, 2022

meet with the same issue in multi-screen scene

@mostcute
Copy link

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

@xuehaonan27
Copy link

Maybe I've found the reason and fixed it.
PR: #697
Detail here: #697 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants