mirror of
https://github.com/go-vgo/robotgo.git
synced 2025-06-02 23:23:55 +00:00
update code and add func PointInBounds
This commit is contained in:
parent
5971e02e26
commit
7a1ffa66a9
@ -117,6 +117,18 @@ MMPoint aFindBitmap(MMBitmapRef bit_map, MMRect rect){
|
|||||||
return point;
|
return point;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool point_in_bounds(MMBitmapRef bitmap, MMPoint point){
|
||||||
|
if (!bitmap_ready(bitmap)) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (MMBitmapPointInBounds(bitmap, point)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
MMBitmapRef bitmap_open(char *path, uint16_t ttype){
|
MMBitmapRef bitmap_open(char *path, uint16_t ttype){
|
||||||
// MMImageType type;
|
// MMImageType type;
|
||||||
|
|
||||||
@ -146,7 +158,7 @@ char *bitmap_save(MMBitmapRef bitmap, char *path, uint16_t type){
|
|||||||
if (saveMMBitmapToFile(bitmap, path, (MMImageType) type) != 0) {
|
if (saveMMBitmapToFile(bitmap, path, (MMImageType) type) != 0) {
|
||||||
return "Could not save image to file.";
|
return "Could not save image to file.";
|
||||||
}
|
}
|
||||||
//destroyMMBitmap(bitmap);
|
// destroyMMBitmap(bitmap);
|
||||||
return "ok";
|
return "ok";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
32
robotgo.go
32
robotgo.go
@ -62,7 +62,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
version string = "v0.47.0.442, Mount Cook!"
|
version string = "v0.47.0.445, Mount Cook!"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
@ -165,7 +165,7 @@ func CaptureScreen(args ...int) C.MMBitmapRef {
|
|||||||
// fmt.Println("err:::", e)
|
// fmt.Println("err:::", e)
|
||||||
x = 0
|
x = 0
|
||||||
y = 0
|
y = 0
|
||||||
//Get screen size.
|
// Get screen size.
|
||||||
var displaySize C.MMSize
|
var displaySize C.MMSize
|
||||||
displaySize = C.getMainDisplaySize()
|
displaySize = C.getMainDisplaySize()
|
||||||
w = displaySize.width
|
w = displaySize.width
|
||||||
@ -286,7 +286,7 @@ func SaveCapture(spath string, args ...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
|
||||||
cx := C.size_t(x)
|
cx := C.size_t(x)
|
||||||
cy := C.size_t(y)
|
cy := C.size_t(y)
|
||||||
C.aMoveMouse(cx, cy)
|
C.aMoveMouse(cx, cy)
|
||||||
@ -483,8 +483,8 @@ func KeyTap(args ...interface{}) {
|
|||||||
keyarr []string
|
keyarr []string
|
||||||
num int
|
num int
|
||||||
)
|
)
|
||||||
// var ckeyarr []*C.char
|
// var ckeyArr []*C.char
|
||||||
ckeyarr := make([](*_Ctype_char), 0)
|
ckeyArr := make([](*_Ctype_char), 0)
|
||||||
|
|
||||||
Try(func() {
|
Try(func() {
|
||||||
if reflect.TypeOf(args[1]) == reflect.TypeOf(keyarr) {
|
if reflect.TypeOf(args[1]) == reflect.TypeOf(keyarr) {
|
||||||
@ -494,7 +494,7 @@ func KeyTap(args ...interface{}) {
|
|||||||
num = len(keyarr)
|
num = len(keyarr)
|
||||||
|
|
||||||
for i := 0; i < num; i++ {
|
for i := 0; i < num; i++ {
|
||||||
ckeyarr = append(ckeyarr, (*C.char)(unsafe.Pointer(C.CString(keyarr[i]))))
|
ckeyArr = append(ckeyArr, (*C.char)(unsafe.Pointer(C.CString(keyarr[i]))))
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -519,7 +519,7 @@ func KeyTap(args ...interface{}) {
|
|||||||
zkey := C.CString(args[0].(string))
|
zkey := C.CString(args[0].(string))
|
||||||
|
|
||||||
if akey == "" && len(keyarr) != 0 {
|
if akey == "" && len(keyarr) != 0 {
|
||||||
C.aKey_Tap(zkey, (**_Ctype_char)(unsafe.Pointer(&ckeyarr[0])), C.int(num))
|
C.aKey_Tap(zkey, (**_Ctype_char)(unsafe.Pointer(&ckeyArr[0])), C.int(num))
|
||||||
} else {
|
} else {
|
||||||
// zkey := C.CString(args[0])
|
// zkey := C.CString(args[0])
|
||||||
amod := C.CString(akey)
|
amod := C.CString(akey)
|
||||||
@ -547,18 +547,18 @@ func KeyToggle(args ...string) string {
|
|||||||
|
|
||||||
Try(func() {
|
Try(func() {
|
||||||
adown = args[1]
|
adown = args[1]
|
||||||
Try(func() {
|
if len(args) > 2 {
|
||||||
amkey = args[2]
|
amkey = args[2]
|
||||||
|
|
||||||
Try(func() {
|
Try(func() {
|
||||||
amkeyt = args[3]
|
amkeyt = args[3]
|
||||||
}, func(e interface{}) {
|
}, func(e interface{}) {
|
||||||
// fmt.Println("err:::", e)
|
// fmt.Println("err:::", e)
|
||||||
amkeyt = "null"
|
amkeyt = "null"
|
||||||
})
|
})
|
||||||
}, func(e interface{}) {
|
} else {
|
||||||
// fmt.Println("err:::", e)
|
|
||||||
amkey = "null"
|
amkey = "null"
|
||||||
})
|
}
|
||||||
}, func(e interface{}) {
|
}, func(e interface{}) {
|
||||||
// fmt.Println("err:::", e)
|
// fmt.Println("err:::", e)
|
||||||
adown = "null"
|
adown = "null"
|
||||||
@ -733,6 +733,16 @@ func FindBit(args ...interface{}) (int, int) {
|
|||||||
return int(pos.x), int(pos.y)
|
return int(pos.x), int(pos.y)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PointInBounds bitmap point in bounds
|
||||||
|
func PointInBounds(bitmap C.MMBitmapRef, x, y int) bool {
|
||||||
|
var point C.MMPoint
|
||||||
|
point.x = C.size_t(x)
|
||||||
|
point.y = C.size_t(y)
|
||||||
|
cbool := C.point_in_bounds(bitmap, point)
|
||||||
|
|
||||||
|
return bool(cbool)
|
||||||
|
}
|
||||||
|
|
||||||
// OpenBitmap open the bitmap
|
// OpenBitmap open the bitmap
|
||||||
func OpenBitmap(args ...interface{}) C.MMBitmapRef {
|
func OpenBitmap(args ...interface{}) C.MMBitmapRef {
|
||||||
path := C.CString(args[0].(string))
|
path := C.CString(args[0].(string))
|
||||||
|
4
vendor/vendor.json
vendored
4
vendor/vendor.json
vendored
@ -65,8 +65,8 @@
|
|||||||
{
|
{
|
||||||
"checksumSHA1": "UuwHornIODuEq7fYnsZwdVgERLk=",
|
"checksumSHA1": "UuwHornIODuEq7fYnsZwdVgERLk=",
|
||||||
"path": "github.com/shirou/gopsutil/mem",
|
"path": "github.com/shirou/gopsutil/mem",
|
||||||
"revision": "a8bc26299477e53c4ca89f7ec60160a74d4c0890",
|
"revision": "27389f01ec9364f60d6dba4fbe9751d3b7058d46",
|
||||||
"revisionTime": "2017-11-12T16:40:41Z"
|
"revisionTime": "2017-12-14T06:29:47Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "AiC1wzY1Rjxs7iitVBvn4YM886k=",
|
"checksumSHA1": "AiC1wzY1Rjxs7iitVBvn4YM886k=",
|
||||||
|
Loading…
Reference in New Issue
Block a user