robotgo icon indicating copy to clipboard operation
robotgo copied to clipboard

GetBounds returns wrong values

Open elonzh opened this issue 6 years ago • 7 comments

  • Robotgo version (or commit ref): v0.80.0.845, Sierra Nevada!
  • Go version:
$go version  
go version go1.12 darwin/amd64
  • Gcc version:
$gcc -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/c++/4.2.1
Apple LLVM version 10.0.1 (clang-1001.0.46.3)
Target: x86_64-apple-darwin18.5.0
Thread model: posix
  • Operating system and bit: macOS Mojave x64
  • Resolution: 2880 x 1800
  • Can you reproduce the bug at Examples:
    • [x] Yes (provide example code)
    • [ ] No
    • [ ] Not relevant
  • Provide example code:
package main

import (
	"fmt"
	"strings"

	"github.com/go-vgo/robotgo"
)

func main() {
	fmt.Println("Version:", robotgo.Version)
	process, _ := robotgo.Process()
	for _, p := range process {
		if strings.Contains(strings.ToLower(p.Name), "macpass") {
			mx, my := robotgo.GetMousePos()
			x, y, w, h := robotgo.GetBounds(p.Pid)
			robotgo.SetActive(robotgo.GetHandPid(p.Pid))
			fmt.Println("Bounds:", robotgo.IsValid(), x, y, w, h)
			fmt.Println("MousePos:", mx, my)
			bitmap := robotgo.CaptureScreen()
			defer robotgo.FreeBitmap(bitmap)
			robotgo.SaveBitmap(bitmap, "test.png")
		}
	}
}
  • Log gist:
$go run main.go                                                                       
Version: v0.80.0.845, Sierra Nevada!
Bounds: true 974848 512 -1 197
MousePos: 509 650

Description

test

elonzh avatar Mar 29 '19 07:03 elonzh

Also having the same issue, any investigation done?

bt avatar Sep 10 '19 07:09 bt

Has this progressed?

amlwwalker avatar Oct 24 '19 07:10 amlwwalker

I researched this further as was getting no response here. Turns out osx will return nil when you ask for the bounds of another application and therefore this is not possible.

amlwwalker avatar Nov 16 '19 12:11 amlwwalker

OS: Ubuntu 16.04 Description: the value of X variable is obviously greater than screen size

Code

	fpid, err := robotgo.FindIds("Game")
	if err != nil {
		log.Fatal(err)
	}
	pid := fpid[0]
	fmt.Println("pid: ", pid)
	x, y, w, h := robotgo.GetBounds(pid)
	fmt.Printf("x: %d, y: %d, w: %d, h: %d \n", x, y, w, h)
	sW, sH := robotgo.GetScreenSize()
	fmt.Printf("screen size: %d, %d", sW, sH)

Output

pid:  11806
x: 2555, y: 150, w: 1024, h: 796 
screen size: 1920, 1080

caryyu avatar Jun 27 '20 07:06 caryyu

have the same problem. how to test/debug where goes wrong in win_sys.h Bounds get_bounds(uintptr pid, uintptr isHwnd){

markgician avatar Nov 04 '20 15:11 markgician