mirror of
https://github.com/go-vgo/robotgo.git
synced 2025-06-07 01:03:54 +00:00
commited
This commit is contained in:
parent
6c137427db
commit
99101f5ee7
16
.github/workflows/go.yml
vendored
16
.github/workflows/go.yml
vendored
@ -1,12 +1,16 @@
|
||||
name: Go
|
||||
on: [push]
|
||||
name: Build
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- "**"
|
||||
workflow_dispatch:
|
||||
jobs:
|
||||
test:
|
||||
build-latest:
|
||||
# name: build
|
||||
strategy:
|
||||
matrix:
|
||||
# go: [1.12.x, 1.13.x]
|
||||
os: [macOS-latest, windows-latest] # ubuntu-latest
|
||||
os: [macOS-latest, windows-latest, ubuntu-latest] # ubuntu-latest
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
steps:
|
||||
@ -22,9 +26,9 @@ jobs:
|
||||
- name: Get dependencies
|
||||
run: |
|
||||
go get -v -t -d ./...
|
||||
go build -v ./...
|
||||
|
||||
- name: Build
|
||||
run: go build -v .
|
||||
- name: Test
|
||||
run: go test -v robot_info_test.go
|
||||
# run: go test -v .
|
||||
run: go test -v robot_info_test.go
|
2
doc.go
2
doc.go
@ -8,7 +8,7 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
package robotgo
|
||||
package keyboard
|
||||
|
||||
/*
|
||||
Keys are supported:
|
||||
|
@ -1,166 +0,0 @@
|
||||
# Robotgo examples
|
||||
|
||||
## Install:
|
||||
```
|
||||
go get -u github.com/go-vgo/robotgo
|
||||
```
|
||||
|
||||
## [Examples:](https://github.com/go-vgo/robotgo/blob/master/examples)
|
||||
|
||||
#### [Mouse](https://github.com/go-vgo/robotgo/blob/master/examples/mouse/main.go)
|
||||
|
||||
```Go
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/go-vgo/robotgo"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// robotgo.ScrollMouse(10, "up")
|
||||
robotgo.Scroll(0, 10)
|
||||
robotgo.MouseClick("left", true)
|
||||
robotgo.MoveSmooth(100, 200, 1.0, 100.0)
|
||||
}
|
||||
```
|
||||
|
||||
#### [Keyboard](https://github.com/go-vgo/robotgo/blob/master/examples/key/main.go)
|
||||
|
||||
```Go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/go-vgo/robotgo"
|
||||
)
|
||||
|
||||
func main() {
|
||||
robotgo.TypeStr("Hello World")
|
||||
// robotgo.TypeStr("だんしゃり")
|
||||
robotgo.TypeStr("だんしゃり")
|
||||
// ustr := uint32(robotgo.CharCodeAt("だんしゃり", 0))
|
||||
// robotgo.UnicodeType(ustr)
|
||||
|
||||
robotgo.KeyTap("enter")
|
||||
robotgo.TypeStr("en")
|
||||
robotgo.KeyTap("i", "alt", "command")
|
||||
arr := []string{"alt", "command"}
|
||||
robotgo.KeyTap("i", arr)
|
||||
|
||||
robotgo.WriteAll("Test")
|
||||
text, err := robotgo.ReadAll()
|
||||
if err == nil {
|
||||
fmt.Println(text)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### [Screen](https://github.com/go-vgo/robotgo/blob/master/examples/screen/main.go)
|
||||
|
||||
```Go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/go-vgo/robotgo"
|
||||
)
|
||||
|
||||
func main() {
|
||||
x, y := robotgo.Location()
|
||||
fmt.Println("pos:", x, y)
|
||||
color := robotgo.GetPixelColor(100, 200)
|
||||
fmt.Println("color----", color)
|
||||
}
|
||||
```
|
||||
|
||||
#### [Bitmap](https://github.com/go-vgo/robotgo/blob/master/examples/bitmap/main.go)
|
||||
|
||||
```Go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/go-vgo/robotgo"
|
||||
)
|
||||
|
||||
func main() {
|
||||
bitmap := robotgo.CaptureScreen(10, 20, 30, 40)
|
||||
// use `defer robotgo.FreeBitmap(bit)` to free the bitmap
|
||||
defer robotgo.FreeBitmap(bitmap)
|
||||
fmt.Println("...", bitmap)
|
||||
|
||||
fx, fy := robotgo.FindBitmap(bitmap)
|
||||
fmt.Println("FindBitmap------", fx, fy)
|
||||
|
||||
robotgo.SaveBitmap(bitmap, "test.png")
|
||||
}
|
||||
```
|
||||
|
||||
#### [Event](https://github.com/go-vgo/robotgo/blob/master/examples/event/main.go)
|
||||
|
||||
```Go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/go-vgo/robotgo"
|
||||
)
|
||||
|
||||
func main() {
|
||||
keve := robotgo.AddEvent("k")
|
||||
if keve {
|
||||
fmt.Println("you press...", "k")
|
||||
}
|
||||
|
||||
mleft := robotgo.AddEvent("mleft")
|
||||
if mleft {
|
||||
fmt.Println("you press...", "mouse left button")
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### [Window](https://github.com/go-vgo/robotgo/blob/master/examples/window/main.go)
|
||||
|
||||
```Go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/go-vgo/robotgo"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fpid, err := robotgo.FindIds("Google")
|
||||
if err == nil {
|
||||
fmt.Println("pids...", fpid)
|
||||
|
||||
if len(fpid) > 0 {
|
||||
robotgo.ActivePID(fpid[0])
|
||||
|
||||
robotgo.Kill(fpid[0])
|
||||
}
|
||||
}
|
||||
|
||||
robotgo.ActiveName("chrome")
|
||||
|
||||
isExist, err := robotgo.PidExists(100)
|
||||
if err == nil && isExist {
|
||||
fmt.Println("pid exists is", isExist)
|
||||
|
||||
robotgo.Kill(100)
|
||||
}
|
||||
|
||||
abool := robotgo.ShowAlert("test", "robotgo")
|
||||
if abool == 0 {
|
||||
fmt.Println("ok@@@", "ok")
|
||||
}
|
||||
|
||||
title := robotgo.GetTitle()
|
||||
fmt.Println("title@@@", title)
|
||||
}
|
||||
```
|
@ -1,134 +0,0 @@
|
||||
// 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 main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/go-vgo/robotgo"
|
||||
// "go-vgo/robotgo"
|
||||
)
|
||||
|
||||
func typeStr() {
|
||||
// typing "Hello World"
|
||||
robotgo.TypeStr("Hello World!", 0, 1)
|
||||
robotgo.KeySleep = 100
|
||||
robotgo.TypeStr("だんしゃり")
|
||||
|
||||
robotgo.TypeStr("Hi galaxy, hi stars, hi MT.Rainier, hi sea. こんにちは世界.")
|
||||
robotgo.TypeStr("So, hi, bye! 你好, 再见!")
|
||||
robotgo.Sleep(1)
|
||||
|
||||
robotgo.TypeStr("Hi, Seattle space needle, Golden gate bridge, One world trade center.")
|
||||
robotgo.MilliSleep(100)
|
||||
|
||||
ustr := uint32(robotgo.CharCodeAt("So, hi, bye!", 0))
|
||||
robotgo.UnicodeType(ustr)
|
||||
|
||||
err := robotgo.PasteStr("paste string")
|
||||
fmt.Println("PasteStr: ", err)
|
||||
}
|
||||
|
||||
func keyTap() {
|
||||
// press "enter"
|
||||
robotgo.KeyTap("enter")
|
||||
robotgo.KeyTap(robotgo.Enter)
|
||||
robotgo.KeySleep = 200
|
||||
robotgo.KeyTap("a")
|
||||
robotgo.MilliSleep(100)
|
||||
robotgo.KeyTap("a", "ctrl")
|
||||
|
||||
// hide window
|
||||
err := robotgo.KeyTap("h", "cmd")
|
||||
if err != nil {
|
||||
fmt.Println("robotgo.KeyTap run error is: ", err)
|
||||
}
|
||||
|
||||
robotgo.KeyTap("h", "cmd")
|
||||
|
||||
// press "i", "alt", "command" Key combination
|
||||
robotgo.KeyTap(robotgo.KeyI, robotgo.Alt, robotgo.Cmd)
|
||||
robotgo.KeyTap("i", "alt", "cmd")
|
||||
|
||||
arr := []string{"alt", "cmd"}
|
||||
robotgo.KeyTap("i", arr)
|
||||
robotgo.KeyTap("i", arr)
|
||||
|
||||
robotgo.KeyTap("i", "cmd", " alt", "shift")
|
||||
|
||||
// close window
|
||||
robotgo.KeyTap("w", "cmd")
|
||||
|
||||
// minimize window
|
||||
robotgo.KeyTap("m", "cmd")
|
||||
|
||||
robotgo.KeyTap("f1", "ctrl")
|
||||
robotgo.KeyTap("a", "control")
|
||||
}
|
||||
|
||||
func special() {
|
||||
robotgo.TypeStr("{}")
|
||||
robotgo.KeyTap("[", "]")
|
||||
|
||||
robotgo.KeyToggle("(")
|
||||
robotgo.KeyToggle("(", "up")
|
||||
}
|
||||
|
||||
func keyToggle() {
|
||||
// robotgo.KeySleep = 150
|
||||
robotgo.KeyToggle(robotgo.KeyA)
|
||||
robotgo.KeyToggle("a", "down", "alt")
|
||||
robotgo.Sleep(1)
|
||||
|
||||
robotgo.KeyToggle("a", "up", "alt", "cmd")
|
||||
robotgo.MilliSleep(100)
|
||||
robotgo.KeyToggle("q", "up", "alt", "cmd", "shift")
|
||||
|
||||
err := robotgo.KeyToggle(robotgo.Enter)
|
||||
if err != nil {
|
||||
fmt.Println("robotgo.KeyToggle run error is: ", err)
|
||||
}
|
||||
}
|
||||
|
||||
func cilp() {
|
||||
// robotgo.TypeStr("en")
|
||||
|
||||
// write string to clipboard
|
||||
e := robotgo.WriteAll("テストする")
|
||||
if e != nil {
|
||||
fmt.Println("robotgo.WriteAll err is: ", e)
|
||||
}
|
||||
|
||||
// read string from clipboard
|
||||
text, err := robotgo.ReadAll()
|
||||
if err != nil {
|
||||
fmt.Println("robotgo.ReadAll err is: ", err)
|
||||
}
|
||||
fmt.Println("text: ", text)
|
||||
}
|
||||
|
||||
func key() {
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Control the keyboard
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
typeStr()
|
||||
special()
|
||||
|
||||
keyTap()
|
||||
keyToggle()
|
||||
|
||||
cilp()
|
||||
}
|
||||
|
||||
func main() {
|
||||
key()
|
||||
}
|
26
examples/keyboard/main.go
Normal file
26
examples/keyboard/main.go
Normal file
@ -0,0 +1,26 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
keyboard "github.com/go-vgo/robotgo"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Define a flag to accept the key combination from the command line
|
||||
keysPtr := flag.String("keys", "", "Key combination to be pressed, e.g., 'cmd+shift+F'")
|
||||
flag.Parse()
|
||||
|
||||
// Check if a key combination was provided
|
||||
if *keysPtr == "" {
|
||||
fmt.Println("Please provide a key combination using the -keys flag.")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
keys := strings.Split(*keysPtr, "^")
|
||||
fmt.Printf("keys: %v\n", strings.Join(keys, "^"))
|
||||
keyboard.KeyTap(keys[len(keys)-1], keys[:len(keys)-1])
|
||||
fmt.Printf("Key combination '%s' pressed.\n", *keysPtr)
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
// 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 main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/go-vgo/robotgo"
|
||||
// "go-vgo/robotgo"
|
||||
)
|
||||
|
||||
func main() {
|
||||
ver := robotgo.GetVersion()
|
||||
fmt.Println("robotgo version is: ", ver)
|
||||
|
||||
// Control the keyboard
|
||||
// key()
|
||||
|
||||
// Control the mouse
|
||||
// mouse()
|
||||
|
||||
// Read the screen
|
||||
// screen()
|
||||
|
||||
// Bitmap and image processing
|
||||
// bitmap()
|
||||
|
||||
// Global event listener
|
||||
// event()
|
||||
|
||||
// Window Handle and progress
|
||||
// window()
|
||||
}
|
@ -1,99 +0,0 @@
|
||||
// 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 main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/go-vgo/robotgo"
|
||||
// "go-vgo/robotgo"
|
||||
)
|
||||
|
||||
func move() {
|
||||
robotgo.MouseSleep = 100
|
||||
robotgo.Move(100, 200)
|
||||
robotgo.MoveRelative(10, -200)
|
||||
|
||||
// move the mouse to 100, 200
|
||||
robotgo.Move(100, 200)
|
||||
|
||||
// drag mouse with smooth
|
||||
robotgo.DragSmooth(10, 10)
|
||||
robotgo.DragSmooth(100, 200, 1.0, 100.0)
|
||||
|
||||
// smooth move the mouse to 100, 200
|
||||
robotgo.MoveSmooth(100, 200)
|
||||
robotgo.MoveSmooth(100, 200, 1.0, 100.0)
|
||||
robotgo.MoveSmoothRelative(10, -100, 1.0, 30.0)
|
||||
|
||||
for i := 0; i < 1080; i += 1000 {
|
||||
fmt.Println("i: ", i)
|
||||
// MoveMouse(800, i)
|
||||
robotgo.Move(800, i)
|
||||
}
|
||||
}
|
||||
|
||||
func click() {
|
||||
|
||||
// click the left mouse button
|
||||
robotgo.Click()
|
||||
|
||||
// click the right mouse button
|
||||
robotgo.Click("right", false)
|
||||
|
||||
// double click the left mouse button
|
||||
robotgo.Click("left", true)
|
||||
}
|
||||
|
||||
func get() {
|
||||
// gets the mouse coordinates
|
||||
x, y := robotgo.Location()
|
||||
fmt.Println("pos:", x, y)
|
||||
if x == 456 && y == 586 {
|
||||
fmt.Println("mouse...", "586")
|
||||
}
|
||||
|
||||
robotgo.Move(x, y)
|
||||
}
|
||||
|
||||
func toggleAndScroll() {
|
||||
// scrolls the mouse either up
|
||||
robotgo.ScrollDir(10, "up")
|
||||
robotgo.ScrollDir(10, "right")
|
||||
|
||||
robotgo.Scroll(100, 10)
|
||||
robotgo.Scroll(0, -10)
|
||||
|
||||
robotgo.Toggle("left")
|
||||
robotgo.Toggle("left", "up")
|
||||
|
||||
// toggles the right mouse button
|
||||
robotgo.Toggle("right")
|
||||
robotgo.Toggle("right", "up")
|
||||
}
|
||||
|
||||
func mouse() {
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Control the mouse
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
move()
|
||||
|
||||
click()
|
||||
|
||||
get()
|
||||
|
||||
toggleAndScroll()
|
||||
}
|
||||
|
||||
func main() {
|
||||
mouse()
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/go-vgo/robotgo"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// syscall.NewLazyDLL("user32.dll").NewProc("SetProcessDPIAware").Call()
|
||||
|
||||
width, height := robotgo.GetScaleSize()
|
||||
fmt.Println("get scale screen size: ", width, height)
|
||||
|
||||
bitmap := robotgo.CaptureScreen(0, 0, width, height)
|
||||
defer robotgo.FreeBitmap(bitmap)
|
||||
// bitmap.Save(bitmap, "test.png")
|
||||
robotgo.Save(robotgo.ToImage(bitmap), "test.png")
|
||||
|
||||
robotgo.Scale = true
|
||||
robotgo.Move(10, 10)
|
||||
robotgo.MoveSmooth(100, 100)
|
||||
|
||||
fmt.Println(robotgo.Location())
|
||||
|
||||
num := robotgo.DisplaysNum()
|
||||
for i := 0; i < num; i++ {
|
||||
rect := robotgo.GetScreenRect(i)
|
||||
fmt.Println("rect: ", rect)
|
||||
}
|
||||
}
|
||||
|
||||
func old() {
|
||||
sx := robotgo.ScaleX() // Deprecated
|
||||
s := robotgo.Scale1() // Deprecated, use the ScaleF() function
|
||||
robotx, roboty := 35*s/100, 25*s/100
|
||||
fmt.Println("scale: ", sx, s, " pos: ", robotx, roboty)
|
||||
|
||||
mx, my := robotgo.Location()
|
||||
sx, sy := mx*s/100, my*s/100
|
||||
|
||||
rx, ry, rw, rh := sx, sy, robotx, roboty
|
||||
// bit1 := robotgo.CaptureScreen(10, 20, robotw, roboth)
|
||||
bit1 := robotgo.CaptureScreen(rx, ry, rw, rh)
|
||||
defer robotgo.FreeBitmap(bit1)
|
||||
// bitmap.Save(bit1, "test2.png")
|
||||
robotgo.Save(robotgo.ToImage(bit1), "test2.png")
|
||||
|
||||
clo := robotgo.GetPixelColor(robotx, roboty)
|
||||
fmt.Println("GetPixelColor...", clo)
|
||||
}
|
@ -1,98 +0,0 @@
|
||||
// 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 main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/go-vgo/robotgo"
|
||||
// "go-vgo/robotgo"
|
||||
)
|
||||
|
||||
func bitmap() {
|
||||
bit := robotgo.CaptureScreen()
|
||||
defer robotgo.FreeBitmap(bit)
|
||||
fmt.Println("abitMap...", bit)
|
||||
|
||||
gbit := robotgo.ToBitmap(bit)
|
||||
fmt.Println("bitmap...", gbit.Width)
|
||||
|
||||
gbitMap := robotgo.CaptureGo()
|
||||
fmt.Println("Go CaptureScreen...", gbitMap.Width)
|
||||
// fmt.Println("...", gbitmap.Width, gbitmap.BytesPerPixel)
|
||||
// robotgo.SaveCapture("saveCapture.png", 10, 20, 100, 100)
|
||||
|
||||
img := robotgo.CaptureImg()
|
||||
robotgo.Save(img, "save.png")
|
||||
|
||||
num := robotgo.DisplaysNum()
|
||||
for i := 0; i < num; i++ {
|
||||
robotgo.DisplayID = i
|
||||
img1 := robotgo.CaptureImg()
|
||||
path1 := "save_" + strconv.Itoa(i)
|
||||
robotgo.Save(img1, path1+".png")
|
||||
robotgo.SaveJpeg(img1, path1+".jpeg", 50)
|
||||
|
||||
img2 := robotgo.CaptureImg(10, 10, 20, 20)
|
||||
path2 := "test_" + strconv.Itoa(i)
|
||||
robotgo.Save(img2, path2+".png")
|
||||
robotgo.SaveJpeg(img2, path2+".jpeg", 50)
|
||||
}
|
||||
}
|
||||
|
||||
func color() {
|
||||
// gets the pixel color at 100, 200.
|
||||
color := robotgo.GetPixelColor(100, 200)
|
||||
fmt.Println("color----", color, "-----------------")
|
||||
|
||||
clo := robotgo.GetPxColor(100, 200)
|
||||
fmt.Println("color...", clo)
|
||||
clostr := robotgo.PadHex(clo)
|
||||
fmt.Println("color...", clostr)
|
||||
|
||||
rgb := robotgo.RgbToHex(255, 100, 200)
|
||||
rgbstr := robotgo.PadHex(robotgo.U32ToHex(rgb))
|
||||
fmt.Println("rgb...", rgbstr)
|
||||
|
||||
hex := robotgo.HexToRgb(uint32(rgb))
|
||||
fmt.Println("hex...", hex)
|
||||
hexh := robotgo.PadHex(robotgo.U8ToHex(hex))
|
||||
fmt.Println("HexToRgb...", hexh)
|
||||
|
||||
// gets the pixel color at 10, 20.
|
||||
color2 := robotgo.GetPixelColor(10, 20)
|
||||
fmt.Println("color---", color2)
|
||||
}
|
||||
|
||||
func screen() {
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Read the screen
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bitmap()
|
||||
|
||||
// gets the screen width and height
|
||||
sx, sy := robotgo.GetScreenSize()
|
||||
fmt.Println("get screen size: ", sx, sy)
|
||||
for i := 0; i < robotgo.DisplaysNum(); i++ {
|
||||
s1 := robotgo.ScaleF(i)
|
||||
fmt.Println("ScaleF: ", s1)
|
||||
}
|
||||
sx, sy = robotgo.GetScaleSize()
|
||||
fmt.Println("get screen scale size: ", sx, sy)
|
||||
|
||||
color()
|
||||
}
|
||||
|
||||
func main() {
|
||||
screen()
|
||||
}
|
@ -1,160 +0,0 @@
|
||||
// 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 main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/go-vgo/robotgo"
|
||||
// "go-vgo/robotgo"
|
||||
)
|
||||
|
||||
func alert() {
|
||||
// show Alert Window
|
||||
abool := robotgo.Alert("hello", "robotgo")
|
||||
if abool {
|
||||
fmt.Println("ok@@@", "ok")
|
||||
}
|
||||
robotgo.Alert("hello", "robotgo", "Ok", "Cancel")
|
||||
}
|
||||
|
||||
func get() {
|
||||
// get the current process id
|
||||
pid := robotgo.GetPid()
|
||||
fmt.Println("pid----", pid)
|
||||
|
||||
// get current Window Active
|
||||
mdata := robotgo.GetActive()
|
||||
|
||||
// get current Window Handle
|
||||
hwnd := robotgo.GetHandle()
|
||||
fmt.Println("hwnd---", hwnd)
|
||||
|
||||
// get current Window title
|
||||
title := robotgo.GetTitle()
|
||||
fmt.Println("title-----", title)
|
||||
|
||||
// set Window Active
|
||||
robotgo.SetActive(mdata)
|
||||
}
|
||||
|
||||
func findIds() {
|
||||
// find the process id by the process name
|
||||
fpid, err := robotgo.FindIds("Google")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
if len(fpid) > 0 {
|
||||
robotgo.KeyTap("a", fpid[0])
|
||||
robotgo.TypeStr("Hi galaxy!", fpid[0])
|
||||
|
||||
robotgo.KeyToggle("a", fpid[0], "cmd")
|
||||
robotgo.KeyToggle("a", fpid[0], "cmd", "up")
|
||||
}
|
||||
|
||||
fmt.Println("pids...", fpid)
|
||||
if len(fpid) > 0 {
|
||||
err = robotgo.ActivePid(fpid[0])
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
tl := robotgo.GetTitle(fpid[0])
|
||||
fmt.Println("pid[0] title is: ", tl)
|
||||
|
||||
x, y, w, h := robotgo.GetBounds(fpid[0])
|
||||
fmt.Println("GetBounds is: ", x, y, w, h)
|
||||
|
||||
// Windows
|
||||
// hwnd := robotgo.FindWindow("google")
|
||||
// hwnd := robotgo.GetHWND()
|
||||
robotgo.MinWindow(fpid[0])
|
||||
robotgo.MaxWindow(fpid[0])
|
||||
robotgo.CloseWindow(fpid[0])
|
||||
|
||||
robotgo.Kill(fpid[0])
|
||||
}
|
||||
}
|
||||
|
||||
func active() {
|
||||
robotgo.ActivePid(100)
|
||||
// robotgo.Sleep(2)
|
||||
robotgo.ActiveName("code")
|
||||
robotgo.Sleep(1)
|
||||
robotgo.ActiveName("chrome")
|
||||
}
|
||||
|
||||
func findName() {
|
||||
// find the process name by the process id
|
||||
name, err := robotgo.FindName(100)
|
||||
if err == nil {
|
||||
fmt.Println("name: ", name)
|
||||
}
|
||||
|
||||
// find the all process name
|
||||
names, err := robotgo.FindNames()
|
||||
if err == nil {
|
||||
fmt.Println("name: ", names)
|
||||
}
|
||||
|
||||
p, err := robotgo.FindPath(100)
|
||||
if err == nil {
|
||||
fmt.Println("path: ", p)
|
||||
}
|
||||
}
|
||||
|
||||
func ps() {
|
||||
// determine whether the process exists
|
||||
isExist, err := robotgo.PidExists(100)
|
||||
if err == nil && isExist {
|
||||
fmt.Println("pid exists is", isExist)
|
||||
|
||||
robotgo.Kill(100)
|
||||
}
|
||||
|
||||
// get the all process id
|
||||
pids, err := robotgo.Pids()
|
||||
if err == nil {
|
||||
fmt.Println("pids: ", pids)
|
||||
}
|
||||
|
||||
// get the all process struct
|
||||
ps, err := robotgo.Process()
|
||||
if err == nil {
|
||||
fmt.Println("process: ", ps)
|
||||
}
|
||||
}
|
||||
|
||||
func window() {
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Window Handle
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
alert()
|
||||
//
|
||||
get()
|
||||
|
||||
findIds()
|
||||
active()
|
||||
|
||||
findName()
|
||||
//
|
||||
ps()
|
||||
|
||||
// close current Window
|
||||
robotgo.CloseWindow()
|
||||
}
|
||||
|
||||
func main() {
|
||||
window()
|
||||
}
|
2
img.go
2
img.go
@ -8,7 +8,7 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
package robotgo
|
||||
package keyboard
|
||||
|
||||
import (
|
||||
"image"
|
||||
|
2
key.go
2
key.go
@ -8,7 +8,7 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
package robotgo
|
||||
package keyboard
|
||||
|
||||
/*
|
||||
// #include "key/keycode.h"
|
||||
|
@ -8,7 +8,7 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
package robotgo
|
||||
package keyboard
|
||||
|
||||
import (
|
||||
"github.com/vcaesar/keycode"
|
||||
|
2
ps.go
2
ps.go
@ -8,7 +8,7 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
package robotgo
|
||||
package keyboard
|
||||
|
||||
import ps "github.com/vcaesar/gops"
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
package robotgo_test
|
||||
package keyboard_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
@ -27,7 +27,7 @@ Otherwise, to install the robotgo package, run the command:
|
||||
|
||||
go get -u github.com/go-vgo/robotgo
|
||||
*/
|
||||
package robotgo
|
||||
package keyboard
|
||||
|
||||
/*
|
||||
#cgo darwin CFLAGS: -x objective-c -Wno-deprecated-declarations
|
||||
|
@ -1 +1 @@
|
||||
package robotgo
|
||||
package keyboard
|
||||
|
@ -1 +1 @@
|
||||
package robotgo
|
||||
package keyboard
|
||||
|
@ -1,4 +1,4 @@
|
||||
package robotgo
|
||||
package keyboard
|
||||
|
||||
import "github.com/vcaesar/tt"
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
//go:build darwin
|
||||
// +build darwin
|
||||
|
||||
package robotgo
|
||||
package keyboard
|
||||
|
||||
/*
|
||||
#include <CoreGraphics/CoreGraphics.h>
|
||||
|
@ -11,7 +11,7 @@
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package robotgo
|
||||
package keyboard
|
||||
|
||||
// ScaleF get the system scale val
|
||||
func ScaleF(displayId ...int) float64 {
|
||||
|
@ -11,7 +11,7 @@
|
||||
//go:build darwin || windows
|
||||
// +build darwin windows
|
||||
|
||||
package robotgo
|
||||
package keyboard
|
||||
|
||||
// GetBounds get the window bounds
|
||||
func GetBounds(pid int, args ...int) (int, int, int, int) {
|
||||
|
@ -11,7 +11,7 @@
|
||||
//go:build ocr
|
||||
// +build ocr
|
||||
|
||||
package robotgo
|
||||
package keyboard
|
||||
|
||||
import (
|
||||
"github.com/otiai10/gosseract"
|
||||
|
@ -11,7 +11,7 @@
|
||||
//go:build darwin || windows
|
||||
// +build darwin windows
|
||||
|
||||
package robotgo
|
||||
package keyboard
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
@ -11,7 +11,7 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package robotgo
|
||||
package keyboard
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
|
@ -11,7 +11,7 @@
|
||||
//go:build !darwin && !windows
|
||||
// +build !darwin,!windows
|
||||
|
||||
package robotgo
|
||||
package keyboard
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
@ -8,7 +8,7 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
package robotgo
|
||||
package keyboard
|
||||
|
||||
import (
|
||||
"image"
|
||||
|
@ -1,2 +1,2 @@
|
||||
// +bulid linux,next
|
||||
package robotgo
|
||||
package keyboard
|
||||
|
@ -1,2 +1,2 @@
|
||||
// +bulid windows,next
|
||||
package robotgo
|
||||
package keyboard
|
||||
|
Loading…
Reference in New Issue
Block a user