1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/veni0-robotn

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
Клонировать/Скачать
robotgo.go 12 КБ
Копировать Редактировать Web IDE Исходные данные Просмотреть построчно История
vcaesar Отправлено 04.10.2021 19:06 7014c73
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
// 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 Go native cross-platform system automation.
Please make sure Golang, GCC is installed correctly before installing RobotGo;
See Requirements:
https://github.com/go-vgo/robotgo#requirements
Installation:
go get -u github.com/go-vgo/robotgo
C-shared:
go get -v github.com/vcaesar/gocs
gocs -n robotgo
*/
package main
import "C"
import (
"fmt"
"strings"
"github.com/go-vgo/robotgo"
)
func ch(str string) *C.char {
return C.CString(str)
}
func str(ch *C.char) string {
return C.GoString(ch)
}
func sf(err error) string {
return fmt.Sprintf("%s", err)
}
func ech(err error) *C.char {
return ch(sf(err))
}
func toStr(arr interface{}) string {
return strings.Trim(fmt.Sprint(arr), "[]")
}
//export GetVersion
func GetVersion() *C.char {
s := robotgo.GetVersion()
return ch(s)
}
//export Sleep
func Sleep(tm int) {
robotgo.Sleep(tm)
}
//export MilliSleep
func MilliSleep(tm int) {
robotgo.MilliSleep(tm)
}
//export MSleep
func MSleep(tm float64) {
robotgo.MicroSleep(tm)
}
/*
_______. ______ .______ _______ _______ .__ __.
/ | / || _ \ | ____|| ____|| \ | |
| (----`| ,----'| |_) | | |__ | |__ | \| |
\ \ | | | / | __| | __| | . ` |
.----) | | `----.| |\ \----.| |____ | |____ | |\ |
|_______/ \______|| _| `._____||_______||_______||__| \__|
*/
//export GetPixelColor
func GetPixelColor(x, y int) *C.char {
s := robotgo.GetPixelColor(x, y)
return ch(s)
}
//export GetMouseColor
func GetMouseColor() *C.char {
s := robotgo.GetMouseColor()
return ch(s)
}
//export GetScreenSize
func GetScreenSize() (int, int) {
return robotgo.GetScreenSize()
}
//export GetScaleSize
func GetScaleSize() (int, int) {
return robotgo.GetScaleSize()
}
//export CaptureScreen
func CaptureScreen(x, y, w, h int) (*uint8, int, int,
int, uint8, uint8) {
var bit robotgo.Bitmap
if x == -1 {
bit = robotgo.GoCaptureScreen()
} else {
bit = robotgo.GoCaptureScreen(x, y, w, h)
}
return bit.ImgBuf, bit.Width, bit.Height,
bit.Bytewidth, bit.BitsPixel, bit.BytesPerPixel
}
//export SaveCapture
func SaveCapture(path *C.char, x, y, w, h int) {
if x == -1 {
robotgo.SaveCapture(str(path))
return
}
robotgo.SaveCapture(str(path), x, y, w, h)
}
/*
.___ ___. ______ __ __ _______. _______
| \/ | / __ \ | | | | / || ____|
| \ / | | | | | | | | | | (----`| |__
| |\/| | | | | | | | | | \ \ | __|
| | | | | `--' | | `--' | .----) | | |____
|__| |__| \______/ \______/ |_______/ |_______|
*/
//export MoveMouse
func MoveMouse(x, y int) {
robotgo.Move(x, y)
}
//export DragMouse
func DragMouse(x, y int, args *C.char) {
robotgo.Drag(x, y, str(args))
}
//export MoveSmooth
func MoveSmooth(x, y int, low, high float64) bool {
return robotgo.MoveSmooth(x, y, low, high)
}
//export GetMousePos
func GetMousePos() (int, int) {
return robotgo.GetMousePos()
}
//export Click
func Click(btn *C.char, doublec bool) {
robotgo.Click(str(btn), doublec)
}
//export MouseToggle
func MouseToggle(key, btn *C.char) {
robotgo.MouseToggle(str(key), str(btn))
}
//export Scroll
func Scroll(x, y int) {
robotgo.Scroll(x, y)
}
/*
__ ___ ___________ ____ .______ ______ ___ .______ _______
| |/ / | ____\ \ / / | _ \ / __ \ / \ | _ \ | \
| ' / | |__ \ \/ / | |_) | | | | | / ^ \ | |_) | | .--. |
| < | __| \_ _/ | _ < | | | | / /_\ \ | / | | | |
| . \ | |____ | | | |_) | | `--' | / _____ \ | |\ \----.| '--' |
|__|\__\ |_______| |__| |______/ \______/ /__/ \__\ | _| `._____||_______/
*/
//export KeyTap
func KeyTap(key *C.char, vals *C.char) *C.char {
arr := strings.Split(str(vals), ",")
s := robotgo.KeyTap(str(key), arr)
return ch(s)
}
//export KeyToggle
func KeyToggle(key *C.char, vals *C.char) *C.char {
arr := strings.Split(str(vals), ",")
s := robotgo.KeyToggle(str(key), arr...)
return ch(s)
}
//export TypeStr
func TypeStr(c *C.char, args float64) {
robotgo.TypeStr(str(c), args)
}
//export ReadAll
func ReadAll() (*C.char, *C.char) {
s, err := robotgo.ReadAll()
if err != nil {
return ch(s), ech(err)
}
return ch(s), ch("")
}
func errStr(err error) *C.char {
if err != nil {
return ech(err)
}
return ch("")
}
//export WriteAll
func WriteAll(text *C.char) *C.char {
err := robotgo.WriteAll(str(text))
return errStr(err)
}
//export PasteStr
func PasteStr(text *C.char) {
robotgo.PasteStr(str(text))
}
/*
.______ __ .___________..___ ___. ___ .______
| _ \ | | | || \/ | / \ | _ \
| |_) | | | `---| |----`| \ / | / ^ \ | |_) |
| _ < | | | | | |\/| | / /_\ \ | ___/
| |_) | | | | | | | | | / _____ \ | |
|______/ |__| |__| |__| |__| /__/ \__\ | _|
*/
func toBitmap(imgBuf *uint8, width, height, bytewidth int,
bitsPixel, bytesPerPixel uint8) robotgo.Bitmap {
return robotgo.Bitmap{
ImgBuf: imgBuf,
Width: width,
Height: height,
Bytewidth: bytewidth,
BitsPixel: bitsPixel,
BytesPerPixel: bytesPerPixel,
}
}
//export GetText
func GetText(path *C.char) (*C.char, *C.char) {
s, err := robotgo.GetText(str(path))
if err != nil {
return ch(s), ech(err)
}
return ch(s), ch("")
}
//export OpenBitmapArgs
func OpenBitmapArgs(path *C.char) (*uint8, int, int, int,
uint8, uint8) {
cbit := robotgo.OpenBitmap(str(path))
gbit := robotgo.ToBitmap(cbit)
return gbit.ImgBuf, gbit.Width, gbit.Height, gbit.Bytewidth,
gbit.BitsPixel, gbit.BytesPerPixel
}
//export FreeBitmap
func FreeBitmap(imgBuf *uint8, width, height, bytewidth int,
bitsPixel, bytesPerPixel uint8) {
gbit := toBitmap(imgBuf, width, height, bytewidth, bitsPixel, bytesPerPixel)
cbit := robotgo.ToCBitmap(gbit)
robotgo.FreeBitmap(cbit)
}
//export FindBitmapArgs
func FindBitmapArgs(imgBuf *uint8, width, height, bytewidth int,
bitsPixel, bytesPerPixel uint8) (int, int) {
gbit := toBitmap(imgBuf, width, height, bytewidth, bitsPixel, bytesPerPixel)
cbit := robotgo.ToCBitmap(gbit)
return robotgo.FindBitmap(cbit)
}
//export SaveBitmapArgs
func SaveBitmapArgs(path *C.char, imgBuf *uint8, width, height, bytewidth int,
bitsPixel, bytesPerPixel uint8) *C.char {
gbit := toBitmap(imgBuf, width, height, bytewidth, bitsPixel, bytesPerPixel)
cbit := robotgo.ToCBitmap(gbit)
s := robotgo.SaveBitmap(cbit, str(path))
return ch(s)
}
//export ToStrBitmap
func ToStrBitmap(imgBuf *uint8, width, height, bytewidth int,
bitsPixel, bytesPerPixel uint8) *C.char {
gbit := toBitmap(imgBuf, width, height, bytewidth, bitsPixel, bytesPerPixel)
cbit := robotgo.ToCBitmap(gbit)
b := robotgo.TostringBitmap(cbit)
return ch(b)
}
//export BitmapFromStr
func BitmapFromStr(bit *C.char) (*uint8, int, int, int,
uint8, uint8) {
cbit := robotgo.BitmapFromStr(str(bit))
gbit := robotgo.ToBitmap(cbit)
return gbit.ImgBuf, gbit.Width, gbit.Height, gbit.Bytewidth,
gbit.BitsPixel, gbit.BytesPerPixel
}
//export CaptureBitmapStr
func CaptureBitmapStr(x, y, w, h int) *C.char {
bit := robotgo.CaptureScreen(x, y, w, h)
str := robotgo.TostringBitmap(bit)
return ch(str)
}
//export OpenBitmapStr
func OpenBitmapStr(path *C.char) *C.char {
bit := robotgo.OpenBitmap(str(path))
s := robotgo.TostringBitmap(bit)
return ch(s)
}
//export SaveBitmapStr
func SaveBitmapStr(bit, path *C.char) *C.char {
bitmap := robotgo.BitmapStr(str(bit))
err := robotgo.SaveBitmap(bitmap, str(path))
return ch(err)
}
//export FindBitmapStr
func FindBitmapStr(c *C.char) (int, int) {
bit := robotgo.BitmapStr(str(c))
return robotgo.FindBitmap(bit)
}
//export FindPic
func FindPic(path *C.char) (int, int) {
return robotgo.FindPic(str(path))
}
//export GetImgSize
func GetImgSize(path *C.char) (int, int) {
return robotgo.GetImgSize(str(path))
}
//export FindColor
func FindColor(color uint32) (int, int) {
x, y := robotgo.FindColor(robotgo.UintToHex(color))
return x, y
}
//export FindColorCS
func FindColorCS(color uint32, x, y, w, h int) (int, int) {
fx, fy := robotgo.FindColorCS(robotgo.UintToHex(color), x, y, w, h)
return fx, fy
}
/*
___________ ____ _______ .__ __. .___________.
| ____\ \ / / | ____|| \ | | | |
| |__ \ \/ / | |__ | \| | `---| |----`
| __| \ / | __| | . ` | | |
| |____ \ / | |____ | |\ | | |
|_______| \__/ |_______||__| \__| |__|
*/
//export AddEvent
func AddEvent(key *C.char) bool {
return robotgo.AddEvent(str(key))
}
//export StopEvent
func StopEvent() {
robotgo.StopEvent()
}
//export AddEvents
func AddEvents(key, args *C.char) bool {
arr := strings.Split(str(args), ",")
return robotgo.AddEvents(str(key), arr...)
}
//export End
func End() {
robotgo.End()
}
//export AddMouse
func AddMouse(btn *C.char, x, y int16) bool {
if x == -1 {
b := robotgo.AddMouse(str(btn))
return b
}
b := robotgo.AddMouse(str(btn), x, y)
return b
}
//export AddMousePos
func AddMousePos(x, y int16) bool {
b := robotgo.AddMousePos(x, y)
return b
}
/*
____ __ ____ __ .__ __. _______ ______ ____ __ ____
\ \ / \ / / | | | \ | | | \ / __ \ \ \ / \ / /
\ \/ \/ / | | | \| | | .--. | | | | \ \/ \/ /
\ / | | | . ` | | | | | | | | \ /
\ /\ / | | | |\ | | '--' | `--' | \ /\ /
\__/ \__/ |__| |__| \__| |_______/ \______/ \__/ \__/
*/
//export ShowAlert
func ShowAlert(title, msg *C.char) bool {
return robotgo.ShowAlert(str(title), str(msg))
}
//export GetTitle
func GetTitle(pid int32) *C.char {
if pid == -1 {
title := robotgo.GetTitle()
return ch(title)
}
title := robotgo.GetTitle(pid)
return ch(title)
}
//export GetBounds
func GetBounds(pid int32) (int, int, int, int) {
return robotgo.GetBounds(pid)
}
//export PidExists
func PidExists(pid int32) (bool, *C.char) {
b, err := robotgo.PidExists(pid)
if err != nil {
return b, ech(err)
}
return b, ch("")
}
//export FindIds
func FindIds(name *C.char) (*C.char, *C.char) {
arr, err := robotgo.FindIds(str(name))
sb := toStr(arr)
if err != nil {
return ch(sb), ech(err)
}
return ch(sb), ch("")
}
//export FindName
func FindName(pid int32) (*C.char, *C.char) {
sb, err := robotgo.FindName(pid)
if err != nil {
return ch(sb), ech(err)
}
return ch(sb), ch("")
}
//export FindNames
func FindNames() (*C.char, *C.char) {
arr, err := robotgo.FindNames()
sb := toStr(arr)
if err != nil {
return ch(sb), ech(err)
}
return ch(sb), ch("")
}
//export FindPath
func FindPath(pid int32) (*C.char, *C.char) {
sb, err := robotgo.FindPath(pid)
if err != nil {
return ch(sb), ech(err)
}
return ch(sb), ch("")
}
//export ActivePID
func ActivePID(pid int32) (c *C.char) {
err := robotgo.ActivePID(pid)
if err != nil {
c = ech(err)
}
return
}
//export ActiveName
func ActiveName(name *C.char) (c *C.char) {
err := robotgo.ActiveName(str(name))
if err != nil {
c = ech(err)
}
return
}
//export Kill
func Kill(pid int32) *C.char {
err := robotgo.Kill(pid)
return errStr(err)
}
func main() {} // Required but ignored
1
https://api.gitlife.ru/oschina-mirror/veni0-robotn.git
git@api.gitlife.ru:oschina-mirror/veni0-robotn.git
oschina-mirror
veni0-robotn
veni0-robotn
master