robotgo/README_zh.md

333 lines
7.6 KiB
Markdown
Raw Permalink Normal View History

2017-03-14 10:07:12 +00:00
# Robotgo
2018-09-22 13:41:33 +00:00
2019-12-07 18:24:47 +00:00
[![Build Status](https://github.com/go-vgo/robotgo/workflows/Go/badge.svg)](https://github.com/go-vgo/robotgo/commits/master)
2017-01-07 11:18:31 +00:00
[![CircleCI Status](https://circleci.com/gh/go-vgo/robotgo.svg?style=shield)](https://circleci.com/gh/go-vgo/robotgo)
2019-12-07 18:24:47 +00:00
[![Build Status](https://travis-ci.org/go-vgo/robotgo.svg)](https://travis-ci.org/go-vgo/robotgo)
2017-12-11 09:40:55 +00:00
![Appveyor](https://ci.appveyor.com/api/projects/status/github/go-vgo/robotgo?branch=master&svg=true)
2017-01-07 11:18:31 +00:00
[![Go Report Card](https://goreportcard.com/badge/github.com/go-vgo/robotgo)](https://goreportcard.com/report/github.com/go-vgo/robotgo)
[![GoDoc](https://godoc.org/github.com/go-vgo/robotgo?status.svg)](https://godoc.org/github.com/go-vgo/robotgo)
2018-09-22 13:32:44 +00:00
[![GitHub release](https://img.shields.io/github/release/go-vgo/robotgo.svg)](https://github.com/go-vgo/robotgo/releases/latest)
2017-01-07 11:18:31 +00:00
[![Join the chat at https://gitter.im/go-vgo/robotgo](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/go-vgo/robotgo?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
2019-01-09 00:11:01 +00:00
2017-03-18 07:29:07 +00:00
>Golang 跨平台自动化系统,控制键盘鼠标位图和读取屏幕,窗口句柄以及全局事件监听
2019-01-09 00:11:01 +00:00
2016-10-10 07:50:35 +00:00
RobotGo 支持 Mac, Windows, and Linux(X11).
2019-06-30 15:32:27 +00:00
<br>
2019-06-30 15:36:24 +00:00
2017-03-24 13:47:22 +00:00
提 Issues 请到 [Github](https://github.com/go-vgo/robotgo), 便于统一管理和即时更新
2016-10-10 07:50:35 +00:00
2017-03-14 10:07:12 +00:00
## Contents
2017-01-24 15:27:47 +00:00
- [Docs](#docs)
2019-03-11 14:22:10 +00:00
- [Binding](#binding)
2017-01-20 14:18:57 +00:00
- [Requirements](#requirements)
2017-01-17 12:52:42 +00:00
- [Installation](#installation)
- [Update](#update)
- [Examples](#examples)
2018-08-03 12:08:11 +00:00
- [Cross-Compiling](#crosscompiling)
2018-09-06 14:48:50 +00:00
- [Authors](#authors)
2017-03-17 12:18:50 +00:00
- [Plans](#plans)
2017-03-17 12:27:34 +00:00
- [Donate](#donate)
2017-01-17 12:52:42 +00:00
- [Contributors](#contributors)
2017-03-17 06:35:56 +00:00
- [License](#license)
2016-10-10 07:50:35 +00:00
2017-03-14 10:07:12 +00:00
## Docs
2018-07-04 13:02:45 +00:00
- [GoDoc](https://godoc.org/github.com/go-vgo/robotgo)
2017-01-24 19:10:58 +00:00
- [中文文档](https://github.com/go-vgo/robotgo/blob/master/docs/doc_zh.md)&nbsp;&nbsp;&nbsp;
2019-01-09 00:11:01 +00:00
- [English Docs](https://github.com/go-vgo/robotgo/blob/master/docs/doc.md)
2017-01-24 19:10:58 +00:00
2019-03-11 14:22:10 +00:00
## Binding:
[Robotn](https://github.com/vcaesar/robotn), binding JavaScript and other, support more language.
2017-03-14 12:30:54 +00:00
## Requirements:
2017-04-05 13:14:28 +00:00
环境要求:
2016-10-10 07:50:35 +00:00
2018-11-08 17:57:00 +00:00
在安装 RobotGo 之前, 请确保 `Golang、GCC` 被正确安装
2017-01-24 15:27:47 +00:00
2019-01-09 00:11:01 +00:00
### ALL:
2017-01-14 11:59:40 +00:00
```
Golang
2017-12-08 18:32:23 +00:00
2017-01-24 15:27:47 +00:00
GCC
2017-01-14 11:59:40 +00:00
```
2018-12-21 16:07:27 +00:00
2017-03-14 10:07:12 +00:00
#### For Mac OS X:
2017-01-14 11:59:40 +00:00
```
2017-12-08 18:22:06 +00:00
Xcode Command Line Tools
2019-01-09 00:11:01 +00:00
```
2018-12-21 16:07:27 +00:00
2017-03-14 10:07:12 +00:00
#### For Windows:
2017-01-14 11:59:40 +00:00
```
2018-01-31 11:03:39 +00:00
MinGW-w64 (推荐使用) or other GCC
2017-01-14 11:59:40 +00:00
```
2018-12-21 16:07:27 +00:00
2017-03-31 11:30:46 +00:00
#### For everything else (Linux 等其他系统):
2019-01-08 16:51:09 +00:00
2017-01-14 11:59:40 +00:00
```
2018-07-06 11:29:38 +00:00
GCC, libpng
2019-01-09 00:11:01 +00:00
2017-01-14 11:59:40 +00:00
X11 with the XTest extension (also known as the Xtst library)
2016-10-10 07:50:35 +00:00
2017-01-14 11:59:40 +00:00
事件:
2019-01-09 00:11:01 +00:00
2017-03-24 13:47:22 +00:00
xcb, xkb, libxkbcommon
2017-01-14 11:59:40 +00:00
```
2018-12-21 16:07:27 +00:00
2017-03-14 10:07:12 +00:00
##### Ubuntu:
2016-10-24 05:20:36 +00:00
2017-01-14 11:59:40 +00:00
```yml
2017-02-18 10:17:45 +00:00
sudo apt-get install gcc libc6-dev
2017-01-14 11:59:40 +00:00
2019-01-09 00:11:01 +00:00
sudo apt-get install libx11-dev xorg-dev libxtst-dev libpng++-dev
2016-10-29 19:05:41 +00:00
2017-01-14 11:59:40 +00:00
sudo apt-get install xcb libxcb-xkb-dev x11-xkb-utils libx11-xcb-dev libxkbcommon-x11-dev
sudo apt-get install libxkbcommon-dev
sudo apt-get install xsel xclip
2017-06-11 10:56:26 +00:00
2017-01-14 11:59:40 +00:00
```
2016-10-10 07:50:35 +00:00
2017-04-22 08:26:20 +00:00
#### Fedora:
```yml
sudo dnf install libxkbcommon-devel libXtst-devel libxkbcommon-x11-devel xorg-x11-xkb-utils-devel
sudo dnf install libpng-devel
2017-06-11 10:56:26 +00:00
sudo dnf install xsel xclip
2017-04-22 08:26:20 +00:00
```
2018-12-21 16:07:27 +00:00
2017-03-14 10:07:12 +00:00
## Installation:
2017-01-20 14:18:57 +00:00
```
go get github.com/go-vgo/robotgo
```
It's that easy!
2019-01-09 00:11:01 +00:00
png.h: No such file or directory? Please see [issues/47](https://github.com/go-vgo/robotgo/issues/47).
2017-02-18 10:42:04 +00:00
2017-03-14 10:07:12 +00:00
## Update:
2017-01-20 14:18:57 +00:00
```
2019-01-09 00:11:01 +00:00
go get -u github.com/go-vgo/robotgo
2017-01-20 14:18:57 +00:00
```
2018-12-21 16:07:27 +00:00
2018-12-05 17:05:12 +00:00
注意 go1.10.x C 文件编译缓存问题, [golang #24355](https://github.com/golang/go/issues/24355).
`go mod vendor` problem, [golang #26366](https://github.com/golang/go/issues/26366).
2017-01-20 14:18:57 +00:00
2019-01-08 16:51:09 +00:00
2017-05-25 14:36:51 +00:00
## [Examples:](https://github.com/go-vgo/robotgo/blob/master/examples)
2016-10-10 07:50:35 +00:00
2017-06-04 14:53:47 +00:00
#### [鼠标](https://github.com/go-vgo/robotgo/blob/master/examples/mouse/main.go)
2016-10-10 07:50:35 +00:00
```Go
package main
import (
"github.com/go-vgo/robotgo"
)
func main() {
robotgo.ScrollMouse(10, "up")
2017-01-16 07:20:13 +00:00
robotgo.MouseClick("left", true)
2016-11-12 14:15:30 +00:00
robotgo.MoveMouseSmooth(100, 200, 1.0, 100.0)
2019-01-09 00:11:01 +00:00
}
```
2016-10-10 07:50:35 +00:00
2017-06-04 14:53:47 +00:00
#### [键盘](https://github.com/go-vgo/robotgo/blob/master/examples/key/main.go)
2016-10-10 07:50:35 +00:00
```Go
package main
2019-01-09 00:11:01 +00:00
import (
"fmt"
2017-08-04 15:59:19 +00:00
"github.com/go-vgo/robotgo"
2016-10-10 07:50:35 +00:00
)
func main() {
2019-02-12 13:12:48 +00:00
robotgo.TypeStr("Hello World")
2018-01-18 13:46:35 +00:00
robotgo.TypeStr("测试")
2019-12-16 13:32:07 +00:00
// robotgo.TypeString("测试")
2019-01-09 00:11:01 +00:00
2018-08-20 11:32:36 +00:00
robotgo.TypeStr("山达尔星新星军团, galaxy. こんにちは世界.")
robotgo.Sleep(1)
2019-01-09 00:11:01 +00:00
2019-03-01 11:34:59 +00:00
// ustr := uint32(robotgo.CharCodeAt("测试", 0))
// robotgo.UnicodeType(ustr)
2018-01-18 13:46:35 +00:00
2016-10-10 07:50:35 +00:00
robotgo.KeyTap("enter")
2019-03-01 11:34:59 +00:00
// robotgo.TypeString("en")
2016-11-14 10:20:43 +00:00
robotgo.KeyTap("i", "alt", "command")
2019-02-13 11:11:32 +00:00
2016-11-14 10:22:53 +00:00
arr := []string{"alt", "command"}
robotgo.KeyTap("i", arr)
2017-06-11 11:52:03 +00:00
robotgo.WriteAll("测试")
2017-06-11 12:14:53 +00:00
text, err := robotgo.ReadAll()
if err == nil {
fmt.Println(text)
}
2019-01-09 00:11:01 +00:00
}
2016-10-10 07:50:35 +00:00
```
2017-06-04 14:53:47 +00:00
#### [屏幕](https://github.com/go-vgo/robotgo/blob/master/examples/screen/main.go)
2016-10-10 07:50:35 +00:00
```Go
package main
import (
2017-01-24 15:27:47 +00:00
"fmt"
2016-10-10 07:50:35 +00:00
"github.com/go-vgo/robotgo"
)
func main() {
x, y := robotgo.GetMousePos()
2018-11-08 17:57:00 +00:00
fmt.Println("pos: ", x, y)
2019-02-12 13:12:48 +00:00
2016-11-24 08:19:01 +00:00
color := robotgo.GetPixelColor(100, 200)
2017-01-24 15:27:47 +00:00
fmt.Println("color----", color)
2019-01-09 00:11:01 +00:00
}
2016-10-10 07:50:35 +00:00
```
2016-10-30 06:28:27 +00:00
2018-01-11 11:26:10 +00:00
#### [位图](https://github.com/go-vgo/robotgo/blob/master/examples/bitmap/main.go)
2016-10-30 06:28:27 +00:00
```Go
package main
import (
2017-01-24 15:27:47 +00:00
"fmt"
2016-10-30 06:28:27 +00:00
"github.com/go-vgo/robotgo"
)
func main() {
2017-01-24 15:27:47 +00:00
bitmap := robotgo.CaptureScreen(10, 20, 30, 40)
// use `defer robotgo.FreeBitmap(bit)` to free the bitmap
defer robotgo.FreeBitmap(bitmap)
2017-01-24 15:27:47 +00:00
fmt.Println("...", bitmap)
2016-10-30 06:28:27 +00:00
2017-08-24 13:31:42 +00:00
fx, fy := robotgo.FindBitmap(bitmap)
2017-01-24 15:27:47 +00:00
fmt.Println("FindBitmap------", fx, fy)
2016-10-30 06:28:27 +00:00
2017-01-24 15:27:47 +00:00
robotgo.SaveBitmap(bitmap, "test.png")
2019-01-09 00:11:01 +00:00
}
2016-10-30 06:28:27 +00:00
```
2017-06-04 14:53:47 +00:00
#### [事件](https://github.com/go-vgo/robotgo/blob/master/examples/event/main.go)
2016-10-30 06:28:27 +00:00
```Go
package main
import (
2017-01-24 15:27:47 +00:00
"fmt"
2016-10-30 06:28:27 +00:00
"github.com/go-vgo/robotgo"
)
func main() {
2019-02-22 12:37:25 +00:00
ok := robotgo.AddEvents("q", "ctrl", "shift")
2019-02-22 12:42:23 +00:00
if ok {
fmt.Println("add events...")
}
2019-02-22 12:37:25 +00:00
2016-11-12 07:56:07 +00:00
keve := robotgo.AddEvent("k")
if keve {
2018-11-08 17:57:00 +00:00
fmt.Println("you press... ", "k")
2016-10-30 06:32:34 +00:00
}
2016-11-12 07:56:07 +00:00
mleft := robotgo.AddEvent("mleft")
if mleft {
2018-11-08 17:57:00 +00:00
fmt.Println("you press... ", "mouse left button")
2016-10-30 06:32:34 +00:00
}
2019-01-09 00:11:01 +00:00
}
2016-10-30 06:28:27 +00:00
```
2019-01-08 16:51:09 +00:00
2017-06-04 14:53:47 +00:00
#### [窗口句柄](https://github.com/go-vgo/robotgo/blob/master/examples/window/main.go)
2016-11-07 09:08:12 +00:00
```Go
package main
import (
2017-01-24 15:27:47 +00:00
"fmt"
2016-11-07 09:08:12 +00:00
"github.com/go-vgo/robotgo"
)
func main() {
2017-07-01 15:12:19 +00:00
fpid, err := robotgo.FindIds("Google")
if err == nil {
fmt.Println("pids...", fpid)
2018-01-19 12:46:25 +00:00
if len(fpid) > 0 {
robotgo.ActivePID(fpid[0])
2018-02-03 09:42:38 +00:00
robotgo.Kill(fpid[0])
2018-01-19 12:46:25 +00:00
}
2017-07-01 15:12:19 +00:00
}
2018-01-19 12:46:25 +00:00
robotgo.ActiveName("chrome")
2017-07-01 15:12:19 +00:00
isExist, err := robotgo.PidExists(100)
2018-02-03 09:42:38 +00:00
if err == nil && isExist {
2017-07-01 15:12:19 +00:00
fmt.Println("pid exists is", isExist)
2018-02-03 09:42:38 +00:00
robotgo.Kill(100)
2017-07-01 15:12:19 +00:00
}
2016-11-07 10:43:10 +00:00
abool := robotgo.ShowAlert("test", "robotgo")
if abool == 0 {
2018-11-08 17:57:00 +00:00
fmt.Println("ok@@@ ", "ok")
2016-11-07 10:43:10 +00:00
}
2016-11-09 15:11:50 +00:00
2017-01-16 07:20:13 +00:00
title := robotgo.GetTitle()
2018-11-08 17:57:00 +00:00
fmt.Println("title@@@ ", title)
2019-01-09 00:11:01 +00:00
}
2016-11-07 09:08:12 +00:00
```
2017-01-15 09:09:05 +00:00
2018-08-03 12:08:11 +00:00
## CrossCompiling
2018-08-03 12:01:41 +00:00
##### Windows64 to win32
```Go
SET CGO_ENABLED=1
SET GOARCH=386
go build main.go
```
2018-12-21 16:07:27 +00:00
2018-10-22 23:47:34 +00:00
#### Other to windows
2018-08-03 12:01:41 +00:00
```Go
GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ go build -x ./
```
2018-08-05 11:40:06 +00:00
```
2019-01-09 00:11:01 +00:00
// CC=mingw-w64\x86_64-7.2.0-win32-seh-rt_v5-rev1\mingw64\bin\gcc.exe
2018-08-05 11:40:06 +00:00
// CXX=mingw-w64\x86_64-7.2.0-win32-seh-rt_v5-rev1\mingw64\bin\g++.exe
```
2018-08-03 12:01:41 +00:00
2018-09-06 14:48:50 +00:00
## Authors
* [The author is vz](https://github.com/vcaesar)
* [Maintainers](https://github.com/orgs/go-vgo/people)
* [Contributors](https://github.com/go-vgo/robotgo/graphs/contributors)
2017-03-17 12:18:50 +00:00
## Plans
2017-03-04 12:33:05 +00:00
- 更新 Find an image on screen, read pixels from an image
2017-02-13 13:14:11 +00:00
- 更新 Window Handle
2017-03-24 13:47:22 +00:00
- 尝试支持 Android, 也许支持 IOS
2017-01-17 10:50:54 +00:00
2017-03-17 12:27:34 +00:00
## Donate
2017-05-20 10:49:41 +00:00
支持 robotgo, [buy me a coffee](https://github.com/go-vgo/buy-me-a-coffee).
2017-03-17 12:27:34 +00:00
2017-05-20 10:49:41 +00:00
#### Paypal
2017-05-20 10:48:10 +00:00
Donate money by [paypal](https://www.paypal.me/veni0/25) to my account [vzvway@gmail.com](vzvway@gmail.com)
2017-03-14 10:07:12 +00:00
## Contributors
2017-01-17 10:50:54 +00:00
- See [contributors page](https://github.com/go-vgo/robotgo/graphs/contributors) for full list of contributors.
2017-03-17 06:34:46 +00:00
- See [Contribution Guidelines](https://github.com/go-vgo/robotgo/blob/master/CONTRIBUTING.md).
## License
2017-06-11 10:56:26 +00:00
Robotgo is primarily distributed under the terms of both the MIT license and the Apache License (Version 2.0), with portions covered by various BSD-like licenses.
2017-03-17 06:34:46 +00:00
See [LICENSE-APACHE](http://www.apache.org/licenses/LICENSE-2.0), [LICENSE-MIT](https://github.com/go-vgo/robotgo/blob/master/LICENSE).