From ffcf6b26cd3022da12ed16d991de7173dc7dfd80 Mon Sep 17 00:00:00 2001 From: vcaesar Date: Mon, 13 Mar 2023 11:07:26 -0700 Subject: [PATCH] Update: fixed windows scale move and Location(), update godoc --- key.go | 4 ++-- robotgo.go | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/key.go b/key.go index 15e85e6..98c5342 100644 --- a/key.go +++ b/key.go @@ -484,7 +484,7 @@ func toErr(str *C.char) error { // // See keys supported: // -// https://github.com/go-vgo/robotgo/blob/master/docs/keys.md +// https://github.com/go-vgo/robotgo/blob/master/docs/keys.md#keys // // Examples: // @@ -532,7 +532,7 @@ func KeyTap(key string, args ...interface{}) error { // // See keys: // -// https://github.com/go-vgo/robotgo/blob/master/docs/keys.md +// https://github.com/go-vgo/robotgo/blob/master/docs/keys.md#keys // // Examples: // diff --git a/robotgo.go b/robotgo.go index 4c97069..b445a8f 100644 --- a/robotgo.go +++ b/robotgo.go @@ -92,7 +92,7 @@ type ( // // The common type conversion of bitmap: // -// https://github.com/go-vgo/robotgo/blob/master/docs/keys.md +// https://github.com/go-vgo/robotgo/blob/master/docs/keys.md#type-conversion type Bitmap struct { ImgBuf *uint8 Width, Height int @@ -270,6 +270,11 @@ func Scaled0(x int, f float64) int { return int(float64(x) * f) } +// Scaled1 return int(x / f) +func Scaled1(x int, f float64) int { + return int(float64(x) / f) +} + // GetScreenSize get the screen size func GetScreenSize() (int, int) { size := C.getMainDisplaySize() @@ -332,6 +337,7 @@ func CaptureScreen(args ...int) CBitmap { x = C.int32_t(rect.X) y = C.int32_t(rect.Y) } + w = C.int32_t(rect.W) h = C.int32_t(rect.H) } @@ -487,7 +493,7 @@ func CheckMouse(btn string) C.MMMouseButton { func MoveScale(x, y int, displayId ...int) (int, int) { if Scale && runtime.GOOS == "windows" { f := ScaleF() - x, y = Scaled0(x, f), Scaled0(y, f) + x, y = Scaled1(x, f), Scaled1(y, f) } return x, y @@ -611,6 +617,11 @@ func Location() (int, int) { x := int(pos.x) y := int(pos.y) + if runtime.GOOS == "windows" { + f := ScaleF() + x, y = Scaled0(x, f), Scaled0(y, f) + } + return x, y }