robotgo icon indicating copy to clipboard operation
robotgo copied to clipboard

Random/invalid mouse position when code is started as Windows service

Open mikigal opened this issue 3 years ago • 0 comments

  • Robotgo version (or commit ref): v1.0.0-beta5.3 (problem also exists with v0.100.10)
  • Go version: 1.18
  • Gcc version: gcc version 12.1.0 (x86_64-win32-sjlj-rev3, Built by MinGW-W64 project)
  • Operating system and bit: Windows 11 (build 21H2), 64 bit
  • Resolution: 3 displays, every 2560x1440
  • Can you reproduce the bug at Examples:
    • [ ] Yes (provide example code)
    • [ ] No
    • [x] Not relevant
  • Provide example code:
func main() {
	for {
		x, y := robotgo.GetMousePos()
		fmt.Printf("Mouse pos: %d; %d\n", x, y)
		time.Sleep(60 * time.Second)
	}
}
  • Log:
Mouse pos: 6400; 0
Mouse pos: -690802357; 587
Mouse pos: 1280; 0
Mouse pos: 0; 0
Mouse pos: 0; 0
Mouse pos: 0; 0
Mouse pos: -690231853; 587
Mouse pos: -1314403141; 587

Description

I've created Windows service (using nssm, but it won't influence for output, it's just services manager) which runs above code with redirection of stdout to file (for debugging purposes). I tried allowing service to interact with desktop, but it does not fix the issue. Every iteration of loop from above code gives random/invalid (even negative values) mouse position.

I also tried build with go build . -ldflags -H=windowsgui as workaround to hide console window (without service then), then outputs are correct, but every time I'm getting mouse position console appears for few milliseconds.

If this issue is unfixable due to design of Windows' services, how can I totally hide console of app and get mouse position working?

mikigal avatar Aug 02 '22 08:08 mikigal