-
Notifications
You must be signed in to change notification settings - Fork 886
/
main.go
160 lines (129 loc) · 3.14 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
// 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()
}