mirror of
https://github.com/go-vgo/robotgo.git
synced 2025-06-02 23:23:55 +00:00
add FindColorCS, CHex type and update findcolor, code
This commit is contained in:
parent
18029106ac
commit
bec112817b
@ -60,22 +60,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
version string = "v0.46.6.428, Pyrenees Mountains!"
|
version string = "v0.46.6.429, Pyrenees Mountains!"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetVersion get version
|
// Map a map
|
||||||
func GetVersion() string {
|
type Map map[string]interface{}
|
||||||
return version
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
_______. ______ .______ _______ _______ .__ __.
|
|
||||||
/ | / || _ \ | ____|| ____|| \ | |
|
|
||||||
| (----`| ,----'| |_) | | |__ | |__ | \| |
|
|
||||||
\ \ | | | / | __| | __| | . ` |
|
|
||||||
.----) | | `----.| |\ \----.| |____ | |____ | |\ |
|
|
||||||
|_______/ \______|| _| `._____||_______||_______||__| \__|
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Bitmap is Bitmap struct
|
// Bitmap is Bitmap struct
|
||||||
type Bitmap struct {
|
type Bitmap struct {
|
||||||
@ -87,6 +76,36 @@ type Bitmap struct {
|
|||||||
BytesPerPixel uint8
|
BytesPerPixel uint8
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MPoint is MPoint struct
|
||||||
|
type MPoint struct {
|
||||||
|
x int
|
||||||
|
y int
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetVersion get version
|
||||||
|
func GetVersion() string {
|
||||||
|
return version
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try handler(err)
|
||||||
|
func Try(fun func(), handler func(interface{})) {
|
||||||
|
defer func() {
|
||||||
|
if err := recover(); err != nil {
|
||||||
|
handler(err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
fun()
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
_______. ______ .______ _______ _______ .__ __.
|
||||||
|
/ | / || _ \ | ____|| ____|| \ | |
|
||||||
|
| (----`| ,----'| |_) | | |__ | |__ | \| |
|
||||||
|
\ \ | | | / | __| | __| | . ` |
|
||||||
|
.----) | | `----.| |\ \----.| |____ | |____ | |\ |
|
||||||
|
|_______/ \______|| _| `._____||_______||_______||__| \__|
|
||||||
|
*/
|
||||||
|
|
||||||
// GetPixelColor get pixel color
|
// GetPixelColor get pixel color
|
||||||
func GetPixelColor(x, y int) string {
|
func GetPixelColor(x, y int) string {
|
||||||
cx := C.size_t(x)
|
cx := C.size_t(x)
|
||||||
@ -240,12 +259,6 @@ func BCaptureScreen(args ...int) Bitmap {
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// MPoint is MPoint struct
|
|
||||||
type MPoint struct {
|
|
||||||
x int
|
|
||||||
y int
|
|
||||||
}
|
|
||||||
|
|
||||||
// MoveMouse move the mouse
|
// MoveMouse move the mouse
|
||||||
func MoveMouse(x, y int) {
|
func MoveMouse(x, y int) {
|
||||||
//C.size_t int
|
//C.size_t int
|
||||||
@ -434,16 +447,6 @@ func ScrollMouse(x int, y string) {
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Try handler(err)
|
|
||||||
func Try(fun func(), handler func(interface{})) {
|
|
||||||
defer func() {
|
|
||||||
if err := recover(); err != nil {
|
|
||||||
handler(err)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
fun()
|
|
||||||
}
|
|
||||||
|
|
||||||
// KeyTap tap the keyboard;
|
// KeyTap tap the keyboard;
|
||||||
//
|
//
|
||||||
// See keys:
|
// See keys:
|
||||||
@ -626,9 +629,6 @@ func SetKeyboardDelay(x int) {
|
|||||||
|_______| \__/ |_______||__| \__| |__|
|
|_______| \__/ |_______||__| \__| |__|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Map a map
|
|
||||||
type Map map[string]interface{}
|
|
||||||
|
|
||||||
// AddEvent add event listener
|
// AddEvent add event listener
|
||||||
func AddEvent(aeve string) int {
|
func AddEvent(aeve string) int {
|
||||||
keycode := Map{
|
keycode := Map{
|
||||||
|
82
robotgo.go
82
robotgo.go
@ -51,6 +51,7 @@ import "C"
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
// "fmt"
|
// "fmt"
|
||||||
|
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
"runtime"
|
||||||
@ -63,22 +64,15 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
version string = "v0.46.6.428, Pyrenees Mountains!"
|
version string = "v0.46.6.429, Pyrenees Mountains!"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetVersion get version
|
type (
|
||||||
func GetVersion() string {
|
// Map a map
|
||||||
return version
|
Map map[string]interface{}
|
||||||
}
|
// CHex c rgb Hex type
|
||||||
|
CHex C.MMRGBHex
|
||||||
/*
|
)
|
||||||
_______. ______ .______ _______ _______ .__ __.
|
|
||||||
/ | / || _ \ | ____|| ____|| \ | |
|
|
||||||
| (----`| ,----'| |_) | | |__ | |__ | \| |
|
|
||||||
\ \ | | | / | __| | __| | . ` |
|
|
||||||
.----) | | `----.| |\ \----.| |____ | |____ | |\ |
|
|
||||||
|_______/ \______|| _| `._____||_______||_______||__| \__|
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Bitmap is Bitmap struct
|
// Bitmap is Bitmap struct
|
||||||
type Bitmap struct {
|
type Bitmap struct {
|
||||||
@ -90,6 +84,36 @@ type Bitmap struct {
|
|||||||
BytesPerPixel uint8
|
BytesPerPixel uint8
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MPoint is MPoint struct
|
||||||
|
type MPoint struct {
|
||||||
|
x int
|
||||||
|
y int
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetVersion get version
|
||||||
|
func GetVersion() string {
|
||||||
|
return version
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try handler(err)
|
||||||
|
func Try(fun func(), handler func(interface{})) {
|
||||||
|
defer func() {
|
||||||
|
if err := recover(); err != nil {
|
||||||
|
handler(err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
fun()
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
_______. ______ .______ _______ _______ .__ __.
|
||||||
|
/ | / || _ \ | ____|| ____|| \ | |
|
||||||
|
| (----`| ,----'| |_) | | |__ | |__ | \| |
|
||||||
|
\ \ | | | / | __| | __| | . ` |
|
||||||
|
.----) | | `----.| |\ \----.| |____ | |____ | |\ |
|
||||||
|
|_______/ \______|| _| `._____||_______||_______||__| \__|
|
||||||
|
*/
|
||||||
|
|
||||||
// GetPixelColor get pixel color
|
// GetPixelColor get pixel color
|
||||||
func GetPixelColor(x, y int) string {
|
func GetPixelColor(x, y int) string {
|
||||||
cx := C.size_t(x)
|
cx := C.size_t(x)
|
||||||
@ -243,12 +267,6 @@ func BCaptureScreen(args ...int) Bitmap {
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// MPoint is MPoint struct
|
|
||||||
type MPoint struct {
|
|
||||||
x int
|
|
||||||
y int
|
|
||||||
}
|
|
||||||
|
|
||||||
// MoveMouse move the mouse
|
// MoveMouse move the mouse
|
||||||
func MoveMouse(x, y int) {
|
func MoveMouse(x, y int) {
|
||||||
//C.size_t int
|
//C.size_t int
|
||||||
@ -437,16 +455,6 @@ func ScrollMouse(x int, y string) {
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Try handler(err)
|
|
||||||
func Try(fun func(), handler func(interface{})) {
|
|
||||||
defer func() {
|
|
||||||
if err := recover(); err != nil {
|
|
||||||
handler(err)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
fun()
|
|
||||||
}
|
|
||||||
|
|
||||||
// KeyTap tap the keyboard;
|
// KeyTap tap the keyboard;
|
||||||
//
|
//
|
||||||
// See keys:
|
// See keys:
|
||||||
@ -832,7 +840,7 @@ func GetColor(bitmap C.MMBitmapRef, x, y int) C.MMRGBHex {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// FindColor find bitmap color
|
// FindColor find bitmap color
|
||||||
func FindColor(bitmap C.MMBitmapRef, color C.MMRGBHex, args ...float32) (int, int) {
|
func FindColor(bitmap C.MMBitmapRef, color CHex, args ...float32) (int, int) {
|
||||||
var tolerance C.float
|
var tolerance C.float
|
||||||
|
|
||||||
if len(args) > 2 {
|
if len(args) > 2 {
|
||||||
@ -841,13 +849,20 @@ func FindColor(bitmap C.MMBitmapRef, color C.MMRGBHex, args ...float32) (int, in
|
|||||||
tolerance = 0.5
|
tolerance = 0.5
|
||||||
}
|
}
|
||||||
|
|
||||||
pos := C.bitmap_find_color(bitmap, color, tolerance)
|
pos := C.bitmap_find_color(bitmap, C.MMRGBHex(color), tolerance)
|
||||||
x := int(pos.x)
|
x := int(pos.x)
|
||||||
y := int(pos.y)
|
y := int(pos.y)
|
||||||
|
|
||||||
return x, y
|
return x, y
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FindColorCS findcolor by CaptureScreen
|
||||||
|
func FindColorCS(x, y, w, h int, color CHex) (int, int) {
|
||||||
|
bitmap := CaptureScreen(x, y, w, h)
|
||||||
|
rx, ry := FindColor(bitmap, color)
|
||||||
|
return rx, ry
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
___________ ____ _______ .__ __. .___________.
|
___________ ____ _______ .__ __. .___________.
|
||||||
| ____\ \ / / | ____|| \ | | | |
|
| ____\ \ / / | ____|| \ | | | |
|
||||||
@ -857,9 +872,6 @@ func FindColor(bitmap C.MMBitmapRef, color C.MMRGBHex, args ...float32) (int, in
|
|||||||
|_______| \__/ |_______||__| \__| |__|
|
|_______| \__/ |_______||__| \__| |__|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Map a map
|
|
||||||
type Map map[string]interface{}
|
|
||||||
|
|
||||||
// AddEvent add event listener
|
// AddEvent add event listener
|
||||||
func AddEvent(aeve string) int {
|
func AddEvent(aeve string) int {
|
||||||
keycode := Map{
|
keycode := Map{
|
||||||
|
Loading…
Reference in New Issue
Block a user