mirror of
https://github.com/go-vgo/robotgo.git
synced 2025-05-30 22:13:54 +00:00
Add: add more capture screens hot support and fixed bug
This commit is contained in:
parent
23d3df9027
commit
73a40e7861
3
go.mod
3
go.mod
@ -3,6 +3,7 @@ module github.com/go-vgo/robotgo
|
||||
go 1.17
|
||||
|
||||
require (
|
||||
github.com/kbinani/screenshot v0.0.0-20210720154843-7d3a670d8329
|
||||
github.com/lxn/win v0.0.0-20210218163916-a377121e959e
|
||||
github.com/otiai10/gosseract v2.2.1+incompatible
|
||||
// github.com/robotn/gohook v0.31.3
|
||||
@ -16,7 +17,9 @@ require (
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/gen2brain/shm v0.0.0-20200228170931-49f9650110c5 // indirect
|
||||
github.com/go-ole/go-ole v1.2.6 // indirect
|
||||
github.com/jezek/xgb v0.0.0-20210312150743-0e0f116e1240 // indirect
|
||||
github.com/lufia/plan9stats v0.0.0-20220913051719-115f729f3c8c // indirect
|
||||
github.com/otiai10/mint v1.3.0 // indirect
|
||||
github.com/power-devops/perfstat v0.0.0-20220216144756-c35f1ee13d7c // indirect
|
||||
|
6
go.sum
6
go.sum
@ -3,11 +3,17 @@ github.com/BurntSushi/graphics-go v0.0.0-20160129215708-b43f31a4a966/go.mod h1:M
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/gen2brain/shm v0.0.0-20200228170931-49f9650110c5 h1:Y5Q2mEwfzjMt5+3u70Gtw93ZOu2UuPeeeTBDntF7FoY=
|
||||
github.com/gen2brain/shm v0.0.0-20200228170931-49f9650110c5/go.mod h1:uF6rMu/1nvu+5DpiRLwusA6xB8zlkNoGzKn8lmYONUo=
|
||||
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
|
||||
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
|
||||
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/jezek/xgb v0.0.0-20210312150743-0e0f116e1240 h1:dy+DS31tGEGCsZzB45HmJJNHjur8GDgtRNX9U7HnSX4=
|
||||
github.com/jezek/xgb v0.0.0-20210312150743-0e0f116e1240/go.mod h1:3P4UH/k22rXyHIJD2w4h2XMqPX4Of/eySEZq9L6wqc4=
|
||||
github.com/kbinani/screenshot v0.0.0-20210720154843-7d3a670d8329 h1:qq2nCpSrXrmvDGRxW0ruW9BVEV1CN2a9YDOExdt+U0o=
|
||||
github.com/kbinani/screenshot v0.0.0-20210720154843-7d3a670d8329/go.mod h1:2VPVQDR4wO7KXHwP+DAypEy67rXf+okUx2zjgpCxZw4=
|
||||
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I=
|
||||
github.com/lufia/plan9stats v0.0.0-20220913051719-115f729f3c8c h1:VtwQ41oftZwlMnOEbMWQtSEUgU64U4s+GHk7hZK+jtY=
|
||||
github.com/lufia/plan9stats v0.0.0-20220913051719-115f729f3c8c/go.mod h1:JKx41uQRwqlTZabZc+kILPrO/3jlKnQ2Z8b7YiVw5cE=
|
||||
|
@ -311,8 +311,8 @@ bool smoothlyMoveMouse(MMPointInt32 endPoint, double lowSpeed, double highSpeed)
|
||||
velo_x /= veloDistance;
|
||||
velo_y /= veloDistance;
|
||||
|
||||
pos.x += floor(velo_x + 0.8);
|
||||
pos.y += floor(velo_y + 0.8);
|
||||
pos.x += floor(velo_x + 0.5);
|
||||
pos.y += floor(velo_y + 0.5);
|
||||
|
||||
/* Make sure we are in the screen boundaries! (Strange things will happen if we are not.) */
|
||||
// if (pos.x >= screenSize.w || pos.y >= screenSize.h) {
|
||||
|
@ -324,8 +324,10 @@ func CaptureScreen(args ...int) CBitmap {
|
||||
} else {
|
||||
// Get the main screen rect.
|
||||
rect := GetScreenRect(displayId)
|
||||
// x = C.int32_t(rect.X)
|
||||
// y = C.int32_t(rect.Y)
|
||||
if runtime.GOOS == "windows" {
|
||||
x = C.int32_t(rect.X)
|
||||
y = C.int32_t(rect.Y)
|
||||
}
|
||||
w = C.int32_t(rect.W)
|
||||
h = C.int32_t(rect.H)
|
||||
}
|
||||
|
52
screen.go
Normal file
52
screen.go
Normal file
@ -0,0 +1,52 @@
|
||||
// Copyright 2016 The go-vgo Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// https://github.com/go-vgo/robotgo/blob/master/LICENSE
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
package robotgo
|
||||
|
||||
import (
|
||||
"image"
|
||||
|
||||
"github.com/kbinani/screenshot"
|
||||
)
|
||||
|
||||
// GetScreenBound gets the display screen bounds
|
||||
func GetDisplayBounds(i int) (x, y, w, h int) {
|
||||
bs := screenshot.GetDisplayBounds(i)
|
||||
return bs.Min.X, bs.Min.Y, bs.Dx(), bs.Dy()
|
||||
}
|
||||
|
||||
// GetDisplayBounds gets the display rect
|
||||
func GetDisplayRect(i int) Rect {
|
||||
x, y, w, h := GetDisplayBounds(i)
|
||||
return Rect{
|
||||
Point{X: x, Y: y},
|
||||
Size{W: w, H: h}}
|
||||
}
|
||||
|
||||
// Capture capture the screenshot
|
||||
func Capture(args ...int) (*image.RGBA, error) {
|
||||
displayId := 0
|
||||
if DisplayID != -1 {
|
||||
displayId = DisplayID
|
||||
}
|
||||
|
||||
if len(args) > 4 {
|
||||
displayId = args[4]
|
||||
}
|
||||
|
||||
var x, y, w, h int
|
||||
if len(args) > 3 {
|
||||
x, y, w, h = args[0], args[1], args[2], args[3]
|
||||
} else {
|
||||
x, y, w, h = GetDisplayBounds(displayId)
|
||||
}
|
||||
|
||||
return screenshot.Capture(x, y, w, h)
|
||||
}
|
Loading…
Reference in New Issue
Block a user