mirror of
https://github.com/go-vgo/robotgo.git
synced 2025-06-04 16:03:54 +00:00
Add golint
This commit is contained in:
parent
8ef848cf3a
commit
5b3d21640c
44
robotgo.go
44
robotgo.go
@ -46,6 +46,7 @@ import (
|
|||||||
|_______/ \______|| _| `._____||_______||_______||__| \__|
|
|_______/ \______|| _| `._____||_______||_______||__| \__|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
//Bitmap struct
|
||||||
type Bit_map struct {
|
type Bit_map struct {
|
||||||
ImageBuffer *uint8
|
ImageBuffer *uint8
|
||||||
Width int
|
Width int
|
||||||
@ -55,6 +56,7 @@ type Bit_map struct {
|
|||||||
BytesPerPixel uint8
|
BytesPerPixel uint8
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//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)
|
||||||
cy := C.size_t(y)
|
cy := C.size_t(y)
|
||||||
@ -65,12 +67,14 @@ func GetPixelColor(x, y int) string {
|
|||||||
return gcolor
|
return gcolor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Get Screen Size
|
||||||
func GetScreenSize() (int, int) {
|
func GetScreenSize() (int, int) {
|
||||||
size := C.aGetScreenSize()
|
size := C.aGetScreenSize()
|
||||||
// Println("...", size, size.width)
|
// Println("...", size, size.width)
|
||||||
return int(size.width), int(size.height)
|
return int(size.width), int(size.height)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Get XDisplay Name
|
||||||
func GetXDisplayName() string {
|
func GetXDisplayName() string {
|
||||||
name := C.aGetXDisplayName()
|
name := C.aGetXDisplayName()
|
||||||
gname := C.GoString(name)
|
gname := C.GoString(name)
|
||||||
@ -78,6 +82,7 @@ func GetXDisplayName() string {
|
|||||||
return gname
|
return gname
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Set XDisplay Name
|
||||||
func SetXDisplayName(name string) string {
|
func SetXDisplayName(name string) string {
|
||||||
cname := C.CString(name)
|
cname := C.CString(name)
|
||||||
str := C.aSetXDisplayName(cname)
|
str := C.aSetXDisplayName(cname)
|
||||||
@ -85,6 +90,7 @@ func SetXDisplayName(name string) string {
|
|||||||
return gstr
|
return gstr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Capture Screen
|
||||||
func CaptureScreen(args ...int) C.MMBitmapRef {
|
func CaptureScreen(args ...int) C.MMBitmapRef {
|
||||||
var x C.size_t
|
var x C.size_t
|
||||||
var y C.size_t
|
var y C.size_t
|
||||||
@ -111,6 +117,7 @@ func CaptureScreen(args ...int) C.MMBitmapRef {
|
|||||||
return bit
|
return bit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Capture Screen
|
||||||
func Capture_Screen(args ...int) Bit_map {
|
func Capture_Screen(args ...int) Bit_map {
|
||||||
var x C.size_t
|
var x C.size_t
|
||||||
var y C.size_t
|
var y C.size_t
|
||||||
@ -156,24 +163,28 @@ func Capture_Screen(args ...int) Bit_map {
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
//MPoint struct
|
||||||
type MPoint struct {
|
type MPoint struct {
|
||||||
x int
|
x int
|
||||||
y int
|
y int
|
||||||
}
|
}
|
||||||
|
|
||||||
//C.size_t int
|
//C.size_t int
|
||||||
|
//Move the Mouse
|
||||||
func MoveMouse(x, y int) {
|
func MoveMouse(x, y 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Drag the Mouse
|
||||||
func DragMouse(x, y int) {
|
func DragMouse(x, y int) {
|
||||||
cx := C.size_t(x)
|
cx := C.size_t(x)
|
||||||
cy := C.size_t(y)
|
cy := C.size_t(y)
|
||||||
C.aDragMouse(cx, cy)
|
C.aDragMouse(cx, cy)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Move Mouse Smooth
|
||||||
func MoveMouseSmooth(x, y int, args ...float64) {
|
func MoveMouseSmooth(x, y int, args ...float64) {
|
||||||
cx := C.size_t(x)
|
cx := C.size_t(x)
|
||||||
cy := C.size_t(y)
|
cy := C.size_t(y)
|
||||||
@ -195,6 +206,7 @@ func MoveMouseSmooth(x, y int, args ...float64) {
|
|||||||
C.aMoveMouseSmooth(cx, cy, low, high)
|
C.aMoveMouseSmooth(cx, cy, low, high)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get Mouse Portion
|
||||||
func GetMousePos() (int, int) {
|
func GetMousePos() (int, int) {
|
||||||
pos := C.aGetMousePos()
|
pos := C.aGetMousePos()
|
||||||
// Println("pos:###", pos, pos.x, pos.y)
|
// Println("pos:###", pos, pos.x, pos.y)
|
||||||
@ -204,6 +216,7 @@ func GetMousePos() (int, int) {
|
|||||||
return x, y
|
return x, y
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//MouseClick
|
||||||
func MouseClick(args ...interface{}) {
|
func MouseClick(args ...interface{}) {
|
||||||
var button C.MMMouseButton
|
var button C.MMMouseButton
|
||||||
var double C.bool
|
var double C.bool
|
||||||
@ -227,6 +240,7 @@ func MouseClick(args ...interface{}) {
|
|||||||
C.aMouseClick(button, double)
|
C.aMouseClick(button, double)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Toggle the Mouse
|
||||||
func MouseToggle(args ...interface{}) {
|
func MouseToggle(args ...interface{}) {
|
||||||
var button C.MMMouseButton
|
var button C.MMMouseButton
|
||||||
Try(func() {
|
Try(func() {
|
||||||
@ -248,11 +262,13 @@ func MouseToggle(args ...interface{}) {
|
|||||||
C.aMouseToggle(down, button)
|
C.aMouseToggle(down, button)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Set Mouse Delay
|
||||||
func SetMouseDelay(x int) {
|
func SetMouseDelay(x int) {
|
||||||
cx := C.size_t(x)
|
cx := C.size_t(x)
|
||||||
C.aSetMouseDelay(cx)
|
C.aSetMouseDelay(cx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Scroll the Mouse
|
||||||
func ScrollMouse(x int, y string) {
|
func ScrollMouse(x int, y string) {
|
||||||
cx := C.size_t(x)
|
cx := C.size_t(x)
|
||||||
z := C.CString(y)
|
z := C.CString(y)
|
||||||
@ -269,6 +285,8 @@ func ScrollMouse(x int, y string) {
|
|||||||
|__|\__\ |_______| |__| |______/ \______/ /__/ \__\ | _| `._____||_______/
|
|__|\__\ |_______| |__| |______/ \______/ /__/ \__\ | _| `._____||_______/
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
//Try
|
||||||
func Try(fun func(), handler func(interface{})) {
|
func Try(fun func(), handler func(interface{})) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if err := recover(); err != nil {
|
if err := recover(); err != nil {
|
||||||
@ -278,6 +296,7 @@ func Try(fun func(), handler func(interface{})) {
|
|||||||
fun()
|
fun()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Keyboard Tap
|
||||||
func KeyTap(args ...interface{}) {
|
func KeyTap(args ...interface{}) {
|
||||||
var akey string
|
var akey string
|
||||||
var akeyt string
|
var akeyt string
|
||||||
@ -334,6 +353,7 @@ func KeyTap(args ...interface{}) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Keyboard Toggle
|
||||||
func KeyToggle(args ...string) {
|
func KeyToggle(args ...string) {
|
||||||
var adown string
|
var adown string
|
||||||
var amkey string
|
var amkey string
|
||||||
@ -371,12 +391,14 @@ func KeyToggle(args ...string) {
|
|||||||
defer C.free(unsafe.Pointer(camkeyt))
|
defer C.free(unsafe.Pointer(camkeyt))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Type String
|
||||||
func TypeString(x string) {
|
func TypeString(x string) {
|
||||||
cx := C.CString(x)
|
cx := C.CString(x)
|
||||||
C.aTypeString(cx)
|
C.aTypeString(cx)
|
||||||
defer C.free(unsafe.Pointer(cx))
|
defer C.free(unsafe.Pointer(cx))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Type String Delayed
|
||||||
func TypeStringDelayed(x string, y int) {
|
func TypeStringDelayed(x string, y int) {
|
||||||
cx := C.CString(x)
|
cx := C.CString(x)
|
||||||
cy := C.size_t(y)
|
cy := C.size_t(y)
|
||||||
@ -384,6 +406,7 @@ func TypeStringDelayed(x string, y int) {
|
|||||||
defer C.free(unsafe.Pointer(cx))
|
defer C.free(unsafe.Pointer(cx))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Set Keyboard Delay
|
||||||
func SetKeyboardDelay(x int) {
|
func SetKeyboardDelay(x int) {
|
||||||
C.aSetKeyboardDelay(C.size_t(x))
|
C.aSetKeyboardDelay(C.size_t(x))
|
||||||
}
|
}
|
||||||
@ -396,6 +419,8 @@ func SetKeyboardDelay(x int) {
|
|||||||
| |_) | | | | | | | | | / _____ \ | |
|
| |_) | | | | | | | | | / _____ \ | |
|
||||||
|______/ |__| |__| |__| |__| /__/ \__\ | _|
|
|______/ |__| |__| |__| |__| /__/ \__\ | _|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
//Find the Bitmap
|
||||||
func FindBitmap(args ...interface{}) (int, int) {
|
func FindBitmap(args ...interface{}) (int, int) {
|
||||||
var bit C.MMBitmapRef
|
var bit C.MMBitmapRef
|
||||||
bit = args[0].(C.MMBitmapRef)
|
bit = args[0].(C.MMBitmapRef)
|
||||||
@ -419,6 +444,7 @@ func FindBitmap(args ...interface{}) (int, int) {
|
|||||||
return int(pos.x), int(pos.y)
|
return int(pos.x), int(pos.y)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//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))
|
||||||
var mtype C.uint16_t
|
var mtype C.uint16_t
|
||||||
@ -434,6 +460,7 @@ func OpenBitmap(args ...interface{}) C.MMBitmapRef {
|
|||||||
// defer C.free(unsafe.Pointer(path))
|
// defer C.free(unsafe.Pointer(path))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Save the Bitmap
|
||||||
func SaveBitmap(args ...interface{}) {
|
func SaveBitmap(args ...interface{}) {
|
||||||
var mtype C.uint16_t
|
var mtype C.uint16_t
|
||||||
Try(func() {
|
Try(func() {
|
||||||
@ -453,17 +480,19 @@ func SaveBitmap(args ...interface{}) {
|
|||||||
// func SaveBitmap(bit C.MMBitmapRef, gpath string, mtype C.MMImageType) {
|
// func SaveBitmap(bit C.MMBitmapRef, gpath string, mtype C.MMImageType) {
|
||||||
// path := C.CString(gpath)
|
// path := C.CString(gpath)
|
||||||
// savebit := C.aSaveBitmap(bit, path, mtype)
|
// savebit := C.aSaveBitmap(bit, path, mtype)
|
||||||
// Println("saveing...", savebit)
|
// Println("saving...", savebit)
|
||||||
// // return bit
|
// // return bit
|
||||||
// // defer C.free(unsafe.Pointer(path))
|
// // defer C.free(unsafe.Pointer(path))
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
// Tostring Bitmap
|
||||||
func TostringBitmap(bit C.MMBitmapRef) *C.char {
|
func TostringBitmap(bit C.MMBitmapRef) *C.char {
|
||||||
str_bit := C.aTostringBitmap(bit)
|
str_bit := C.aTostringBitmap(bit)
|
||||||
// Println("...", str_bit)
|
// Println("...", str_bit)
|
||||||
return str_bit
|
return str_bit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Get Portion
|
||||||
func GetPortion(bit C.MMBitmapRef, x, y, w, h C.size_t) C.MMBitmapRef {
|
func GetPortion(bit C.MMBitmapRef, x, y, w, h C.size_t) C.MMBitmapRef {
|
||||||
var rect C.MMRect
|
var rect C.MMRect
|
||||||
rect.origin.x = x
|
rect.origin.x = x
|
||||||
@ -475,6 +504,7 @@ func GetPortion(bit C.MMBitmapRef, x, y, w, h C.size_t) C.MMBitmapRef {
|
|||||||
return pos
|
return pos
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Convert bitmap
|
||||||
func Convert(args ...interface{}) {
|
func Convert(args ...interface{}) {
|
||||||
var mtype int
|
var mtype int
|
||||||
Try(func() {
|
Try(func() {
|
||||||
@ -502,6 +532,8 @@ func Convert(args ...interface{}) {
|
|||||||
************ **** ************ **** **** ****
|
************ **** ************ **** **** ****
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// Add Event
|
||||||
func AddEvent(aeve string) int {
|
func AddEvent(aeve string) int {
|
||||||
cs := C.CString(aeve)
|
cs := C.CString(aeve)
|
||||||
eve := C.aEvent(cs)
|
eve := C.aEvent(cs)
|
||||||
@ -510,6 +542,7 @@ func AddEvent(aeve string) int {
|
|||||||
return geve
|
return geve
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Add Event
|
||||||
func LEvent(aeve string) int {
|
func LEvent(aeve string) int {
|
||||||
cs := C.CString(aeve)
|
cs := C.CString(aeve)
|
||||||
eve := C.aEvent(cs)
|
eve := C.aEvent(cs)
|
||||||
@ -527,6 +560,8 @@ ____ __ ____ __ .__ __. _______ ______ ____ __ ____
|
|||||||
\__/ \__/ |__| |__| \__| |_______/ \______/ \__/ \__/
|
\__/ \__/ |__| |__| \__| |_______/ \______/ \__/ \__/
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
//ShowAlert
|
||||||
func ShowAlert(title, msg string, args ...string) int {
|
func ShowAlert(title, msg string, args ...string) int {
|
||||||
var (
|
var (
|
||||||
// title string
|
// title string
|
||||||
@ -554,6 +589,7 @@ func ShowAlert(title, msg string, args ...string) int {
|
|||||||
return ibool
|
return ibool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Valid the Window
|
||||||
func IsValid() bool {
|
func IsValid() bool {
|
||||||
abool := C.aIsValid()
|
abool := C.aIsValid()
|
||||||
gbool := bool(abool)
|
gbool := bool(abool)
|
||||||
@ -561,20 +597,24 @@ func IsValid() bool {
|
|||||||
return gbool
|
return gbool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Set the Window Active
|
||||||
func SetActive(win C.MData) {
|
func SetActive(win C.MData) {
|
||||||
C.aSetActive(win)
|
C.aSetActive(win)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Get the Active Window
|
||||||
func GetActive() C.MData {
|
func GetActive() C.MData {
|
||||||
mdata := C.aGetActive()
|
mdata := C.aGetActive()
|
||||||
// Println("active----", mdata)
|
// Println("active----", mdata)
|
||||||
return mdata
|
return mdata
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Close the Window
|
||||||
func CloseWindow() {
|
func CloseWindow() {
|
||||||
C.aCloseWindow()
|
C.aCloseWindow()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Get the Window Handle
|
||||||
func GetHandle() int {
|
func GetHandle() int {
|
||||||
hwnd := C.aGetHandle()
|
hwnd := C.aGetHandle()
|
||||||
ghwnd := int(hwnd)
|
ghwnd := int(hwnd)
|
||||||
@ -582,11 +622,13 @@ func GetHandle() int {
|
|||||||
return ghwnd
|
return ghwnd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Set the Window Handle
|
||||||
func SetHandle(hwnd int) {
|
func SetHandle(hwnd int) {
|
||||||
chwnd := C.uintptr(hwnd)
|
chwnd := C.uintptr(hwnd)
|
||||||
C.aSetHandle(chwnd)
|
C.aSetHandle(chwnd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Get the Window Title
|
||||||
func GetTitle() string {
|
func GetTitle() string {
|
||||||
title := C.aGetTitle()
|
title := C.aGetTitle()
|
||||||
gtittle := C.GoString(title)
|
gtittle := C.GoString(title)
|
||||||
|
Loading…
Reference in New Issue
Block a user