robotgo/zh_doc.md

472 lines
8.7 KiB
Markdown
Raw Normal View History

2016-10-09 04:49:14 +00:00
#方法:
2016-10-24 13:52:25 +00:00
##[键盘](#Keyboard)
#####[Keys](#keys)
#####[SetKeyboardDelay](#SetKeyboardDelay)
#####[KeyTap](#KeyTap)
#####[KeyToggle](#KeyToggle)
#####[TypeString](#TypeString)
#####[TypeStringDelayed](#TypeStringDelayed)
##[鼠标](#Mouse)
#####[SetMouseDelay](#SetMouseDelay)
#####[MoveMouse](#MoveMouse)
#####[MoveMouseSmooth](#MoveMouseSmooth)
#####[MouseClick](#MouseClick)
#####[MouseToggle](#MouseToggle)
#####[DragMouse](#DragMouse)
#####[GetMousePos](#GetMousePos)
#####[ScrollMouse](#ScrollMouse)
##[屏幕](#Screen)
#####[GetPixelColor](#GetPixelColor)
#####[GetScreenSize](#GetScreenSize)
#####[CaptureScreen](#CaptureScreen)
#####[GetXDisplayName(Linux)](#GetXDisplayName)
#####[SetXDisplayName(Linux)](#SetXDisplayName)
##[位图](#Bitmap)
2016-10-10 10:58:23 +00:00
This is a work in progress.(工作正在进行中)
2016-10-09 04:49:14 +00:00
2016-10-24 13:52:25 +00:00
#####[FindBitmap](#FindBitmap)
#####[OpenBitmap](#OpenBitmap)
#####[SaveBitmap](#SaveBitmap)
#####[TostringBitmap](#TostringBitmap)
#####[GetPortion](#GetPortion)
2016-10-30 11:26:56 +00:00
#####[Convert](#Convert)
2016-10-20 11:57:28 +00:00
2016-10-30 13:56:26 +00:00
##[事件](#Event)
2016-10-30 13:35:01 +00:00
2016-11-12 07:56:07 +00:00
#####[LEvent](#LEvent)(相当于AddEvent)
#####[AddEvent](#AddEvent)
2016-10-30 13:35:01 +00:00
2016-11-07 08:46:22 +00:00
##[Window](#Window)
This is a work in progress.
#####[ShowAlert(support linux as soon as possible)](#ShowAlert)
2016-11-10 11:17:34 +00:00
#####[CloseWindow](#CloseWindow)
#####[IsValid](#IsValid)
#####[GetActive](#GetActive)
#####[GetHandle](#GetHandle)
#####[GetTitle](#GetTitle)
2016-11-07 08:46:22 +00:00
2016-10-09 05:57:33 +00:00
2016-10-24 13:52:25 +00:00
##<h2 id="Keyboard">键盘</h2>
###<h3 id="SetKeyboardDelay">.SetKeyboardDelay(ms)</h3>
2016-10-09 05:57:33 +00:00
设置键盘延迟(在键盘一个事件后),单位ms,默认值10ms
Sets the delay in milliseconds to sleep after a keyboard event. This is 10ms by default.
####参数:
延迟时间,单位ms
ms - Time to sleep in milliseconds.
2016-10-24 13:52:25 +00:00
###<h3 id="KeyTap">.KeyTap(key, modifier)</h3>
2016-10-09 05:57:33 +00:00
模拟键盘按键
Press a single key.
####参数:
键盘值
修饰值(可选类型, 字符串或者数组(数组类型正在添加中)) - 可选值: alt, command (win), control, and shift.
key - See keys.
modifier (optional, string or array) - Accepts alt, command (win), control, and shift.
2016-10-24 13:52:25 +00:00
###<h3 id="KeyToggle">.KeyToggle(key, down, modifier)</h3>
2016-10-09 05:57:33 +00:00
键盘切换,按住或释放一个键位
Hold down or release a key.
####参数:
key - See keys.
down - Accepts 'down' or 'up'.
modifier (optional, string or array) - Accepts alt, command (mac), control, and shift.
2016-10-24 13:52:25 +00:00
###<h3 id="TypeString">.TypeString(string)</h3>
2016-10-09 05:57:33 +00:00
####参数:
string - The string to send.
2016-10-24 13:52:25 +00:00
###<h3 id="TypeStringDelayed">.TypeStringDelayed(string, cpm)</h3>
2016-10-09 05:57:33 +00:00
####参数:
string - The string to send.
cpm - Characters per minute.
2016-10-24 13:52:25 +00:00
##<h2 id="Mouse">鼠标</h2>
###<h3 id="SetMouseDelay">.SetMouseDelay(ms)</h3>
2016-10-09 05:57:33 +00:00
设置鼠标延迟(在一个鼠标事件后),单位ms,默认值10ms
Sets the delay in milliseconds to sleep after a mouse event. This is 10ms by default.
####参数:
ms - Time to sleep in milliseconds.
2016-10-24 13:52:25 +00:00
###<h3 id="MoveMouse">.MoveMouse(x, y)</h3>
2016-10-09 05:57:33 +00:00
移动鼠标
Moves mouse to x, y instantly, with the mouse button up.
####参数:
x,y
####例子:
```Go
//Move the mouse to 100, 100 on the screen.
2016-10-23 11:51:10 +00:00
robotgo.MoveMouse(100, 100)
2016-10-09 05:57:33 +00:00
```
2016-10-24 13:52:25 +00:00
###<h3 id="MoveMouseSmooth">.MoveMouseSmooth(x, y)</h3>
2016-10-16 10:32:57 +00:00
模拟鼠标向XY平滑移动(像人类一样),用鼠标按钮向上
2016-10-09 05:57:33 +00:00
Moves mouse to x, y human like, with the mouse button up.
####参数:
x,y
2016-11-12 14:15:30 +00:00
lowspeed,highspeed
####例子:
```Go
robotgo.MoveMouseSmooth(100, 200)
robotgo.MoveMouseSmooth(100, 200, 1.0, 100.0)
```
2016-10-09 05:57:33 +00:00
2016-10-24 13:52:25 +00:00
###<h3 id="MouseClick">.MouseClick(button, double)</h3>
2016-10-09 05:57:33 +00:00
鼠标点击
Clicks the mouse.
####参数:
2016-11-12 13:24:19 +00:00
button (optional) - Accepts left, right, or center. Defaults to left.
2016-10-09 05:57:33 +00:00
double (optional) - Set to true to perform a double click. Defaults to false.
####例子:
```Go
2016-10-23 11:51:10 +00:00
robogo.MouseClick()
2016-11-12 13:24:19 +00:00
robogo.MouseClick("left",true)
2016-10-09 05:57:33 +00:00
```
2016-10-24 13:52:25 +00:00
###<h3 id="MouseToggle">.MouseToggle(down, button)</h3>
2016-10-09 05:57:33 +00:00
鼠标切换
Toggles mouse button.
####参数:
down (optional) - Accepts down or up. Defaults to down.
2016-11-12 13:24:19 +00:00
button (optional) - Accepts "left", "right", or "center". Defaults to left.
2016-10-09 05:57:33 +00:00
####例子:
```Go
2016-10-23 11:51:10 +00:00
robotgo.MouseToggle("down")
2016-11-12 13:24:19 +00:00
robotgo.MouseToggle("down", "right")
2016-10-09 05:57:33 +00:00
```
2016-10-24 13:52:25 +00:00
###<h3 id="DragMouse">.DragMouse(x, y)</h3>
2016-10-09 05:57:33 +00:00
拖动鼠标
Moves mouse to x, y instantly, with the mouse button held down.
####参数:
x,y
####例子:
```Go
//Mouse down at 0, 0 and then drag to 100, 100 and release.
2016-10-23 11:51:10 +00:00
robotgo.MoveMouse(0, 0)
robotgo.MouseToggle("down")
robotgo.DragMouse(100, 100)
robotgo.MouseToggle("up")
2016-10-09 05:57:33 +00:00
```
2016-10-24 13:52:25 +00:00
###<h3 id="GetMousePos">.GetMousePos()</h3>
2016-10-14 05:30:47 +00:00
获取鼠标的位置
2016-10-09 05:57:33 +00:00
Gets the mouse coordinates.
####返回值:
Returns an object with keys x and y.
####例子:
```Go
2016-10-23 11:51:10 +00:00
x,y := robotgo.GetMousePos()
2016-10-09 05:57:33 +00:00
fmt.Println("pos:", x, y)
```
2016-10-24 13:52:25 +00:00
###<h3 id="ScrollMouse">.ScrollMouse(magnitude, direction)</h3>
2016-10-09 05:57:33 +00:00
滚动鼠标
Scrolls the mouse either up or down.
####参数:
滚动位置的大小
滚动方向:up(向上滚动) down(向下滚动)
magnitude - The amount to scroll.
direction - Accepts down or up.
####例子:
```Go
2016-10-23 11:51:10 +00:00
robotgo.ScrollMouse(50, "up")
2016-10-09 05:57:33 +00:00
2016-10-23 11:51:10 +00:00
robotgo.ScrollMouse(50, "down")
2016-10-09 05:57:33 +00:00
```
2016-10-24 13:52:25 +00:00
##<h2 id="Screen">屏幕</h2>
###<h3 id="GetPixelColor">.GetPixelColor(x, y)
2016-10-09 05:57:33 +00:00
获取坐标为x,y位置处的颜色
Gets the pixel color at x, y. This function is perfect for getting a pixel or two, but if you'll be reading large portions of the screen use screen.capture.
####参数:
x,y
####返回值:
Returns the hex color code of the pixel at x, y.
2016-10-24 13:52:25 +00:00
###<h3 id="GetScreenSize">.GetScreenSize()</h3>
2016-10-09 05:57:33 +00:00
获取屏幕大小
Gets the screen width and height.
####返回值:
Returns an object with .width and .height.
2016-10-24 13:52:25 +00:00
###<h3 id="CaptureScreen">.CaptureScreen</h3>
2016-10-16 10:32:57 +00:00
//ScreenCapture
2016-10-09 05:57:33 +00:00
获取部分或者全部屏幕
Gets part or all of the screen.
####参数:
x (optional)
y (optional)
height (optional)
width (optional)
If no arguments are provided, screen.capture will get the full screen.
####返回值:
2016-10-22 11:29:41 +00:00
返回一个bitmap object.
2016-10-09 05:57:33 +00:00
2016-10-24 13:52:25 +00:00
##<h2 id="Bitmap">位图</h2>
2016-10-09 05:57:33 +00:00
This is a work in progress.
2016-10-24 13:52:25 +00:00
###<h3 id="FindBitmap">.FindBitmap</h3>
2016-10-20 11:57:28 +00:00
2016-10-22 11:29:41 +00:00
查找bitmap.
2016-10-20 11:57:28 +00:00
2016-10-22 11:29:41 +00:00
####参数:
2016-10-20 11:57:28 +00:00
2016-10-23 15:53:20 +00:00
bitmap;
rect(可选参数): x, y, w, h
2016-10-20 11:57:28 +00:00
####Return:
2016-10-22 11:29:41 +00:00
查找到,返回bitmap的x和y坐标;没有返回nil
2016-10-20 11:57:28 +00:00
2016-10-24 13:52:25 +00:00
###<h3 id="OpenBitmap">.OpenBitmap</h3>
2016-10-20 11:57:28 +00:00
2016-10-22 11:29:41 +00:00
打开bitmap图片.
2016-10-20 11:57:28 +00:00
2016-10-22 11:29:41 +00:00
####参数:
2016-10-20 11:57:28 +00:00
2016-10-30 11:26:56 +00:00
bitmap图片路径,
MMImageType(可选)
2016-10-20 11:57:28 +00:00
2016-10-22 11:29:41 +00:00
####返回值:
2016-10-20 11:57:28 +00:00
2016-10-22 11:29:41 +00:00
返回一个bitmap对象
2016-10-20 11:57:28 +00:00
2016-10-24 13:52:25 +00:00
###<h3 id="SaveBitmap">.SaveBitmap</h3>
2016-10-20 11:57:28 +00:00
2016-10-22 11:29:41 +00:00
保存一个bitmap图片.
2016-10-20 11:57:28 +00:00
2016-10-22 11:29:41 +00:00
####参数:
2016-10-20 11:57:28 +00:00
2016-10-22 11:29:41 +00:00
bitmap对象,
保存路径,
2016-10-20 11:57:28 +00:00
imagetype(int)
2016-10-22 11:29:41 +00:00
####返回值:
2016-10-20 11:57:28 +00:00
2016-10-22 11:29:41 +00:00
保存图片
2016-10-20 11:57:28 +00:00
2016-10-24 13:52:25 +00:00
###<h3 id="TostringBitmap">.TostringBitmap</h3>
2016-10-20 11:57:28 +00:00
2016-10-22 11:29:41 +00:00
将一个bitmap对象转换为字符串对象.
2016-10-20 11:57:28 +00:00
2016-10-22 11:29:41 +00:00
####参数:
2016-10-20 11:57:28 +00:00
2016-10-22 11:29:41 +00:00
bitmap对象
2016-10-20 11:57:28 +00:00
####Return:
2016-10-22 11:29:41 +00:00
返回一个bitmap字符串
2016-10-20 11:57:28 +00:00
2016-10-24 13:52:25 +00:00
###<h3 id="GetPortion">.GetPortion</h3>
2016-10-23 15:53:20 +00:00
bitmap from a portion
####参数:
bitmap,
rect: x, y, w, h
####返回值:
Returns new bitmap object created from a portion of another
2016-10-30 11:26:56 +00:00
###<h3 id="Convert">.Convert(openpath, savepath,MMImageType)</h3>
2016-10-09 05:57:33 +00:00
2016-10-30 11:26:56 +00:00
转换bitmap图片格式
####参数:
openpath,
savepath,
MMImageType(可选)
####例子:
```Go
robotgo.Convert("test.png", "test.tif")
```
2016-10-30 13:35:01 +00:00
##<h2 id="Event">事件</h2>
2016-11-12 07:56:07 +00:00
###<h3 id="AddEvent">.AddEvent(string)</h3>
2016-10-30 13:35:01 +00:00
监听全局事件
####参数:
string
2016-10-30 13:41:10 +00:00
(鼠标参数:mleft mright wheelDown wheelUp wheelLeft wheelRight)
2016-10-30 13:35:01 +00:00
####返回值:
监听成功返回0
####例子:
```Go
package main
import (
. "fmt"
"github.com/go-vgo/robotgo"
)
func main() {
2016-11-12 07:56:07 +00:00
keve := robotgo.AddEvent("k")
2016-10-30 13:35:01 +00:00
if keve == 0 {
Println("you press...", "k")
}
2016-11-12 07:56:07 +00:00
mleft := robotgo.AddEvent("mleft")
2016-10-30 13:35:01 +00:00
if mleft == 0 {
Println("you press...", "mouse left button")
}
}
2016-11-07 08:46:22 +00:00
```
##<h2 id="Window">Window</h2>
###<h3 id="ShowAlert">.ShowAlert(title, msg,defaultButton,cancelButton string)</h3>
Displays alert with the given attributes. If cancelButton is not given, only the defaultButton is displayed
####Arguments:
title(string),
msg(string),
defaultButton(optional string),
cancelButton(optional string)
####Return:
2016-11-07 14:36:28 +00:00
Returns 0(True) if the default button was pressed, or 1(False) if cancelled.
2016-11-10 11:17:34 +00:00
###<h3 id="CloseWindow">.CloseWindow()</h3>
Close the Window
####Arguments:
####Return:
###<h3 id="IsValid">.IsValid()</h3>
Valid the Window
####Arguments:
####Return:
Returns true if a window has been selected
###<h3 id="GetActive">.GetActive()</h3>
Get the Active Window
####Arguments:
####Return:
Returns hwnd
###<h3 id="GetHandle">.GetHandle()</h3>
Get the Window Handle
####Arguments:
####Return:
Returns hwnd
###<h3 id="GetTitle">.GetTitle()</h3>
Get the Window Title
####Arguments:
####Return:
Returns Window Title