-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
76 lines (70 loc) · 1.82 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
package main
import (
"fmt"
"github.com/go-vgo/robotgo"
"math/rand"
"time"
//"github.com/go-vgo/robotgo"
"gopkg.in/yaml.v3"
"io"
"os"
)
type Config struct {
Commands []struct {
Type *string
X *int
Y *int
MinX *int `yaml:"minX"`
MinY *int `yaml:"minY"`
MaxX *int `yaml:"maxX"`
MaxY *int `yaml:"maxY"`
Button *string
MinSleep *int64 `yaml:"minSleep"`
MaxSleep *int64 `yaml:"maxSleep"`
Key *string
Alt *[]interface{}
}
}
func main() {
file, err := os.Open("script.yaml")
if err != nil {
panic("unable to open configuration file script.yaml")
}
rawConfig, err := io.ReadAll(file)
if err != nil {
panic(fmt.Errorf("failed reading script.yaml: %w", err))
}
var config Config
err = yaml.Unmarshal(rawConfig, &config)
if err != nil {
panic(fmt.Errorf("failed to parse script.yaml: %w", err))
}
for {
for _, command := range config.Commands {
switch *command.Type {
case "move":
if command.X != nil && command.Y != nil {
robotgo.MoveSmooth(*command.X, *command.Y)
} else if command.MinX != nil && command.MinY != nil && command.MaxX != nil && command.MaxY != nil {
x := rand.Intn(*command.MaxX-*command.MinX) + *command.MinX
y := rand.Intn(*command.MaxY-*command.MinY) + *command.MinY
robotgo.MoveSmooth(x, y)
} else {
panic(fmt.Sprintf("Invalid move configuration: %+v", command))
}
case "click":
robotgo.Click(*command.Button)
case "sleep":
sleepTime := rand.Int63n(*command.MaxSleep-*command.MinSleep) + *command.MinSleep
fmt.Printf("Sleeping for %d milliseconds.", sleepTime)
time.Sleep(time.Duration(sleepTime) * time.Millisecond)
case "keytap":
if command.Alt == nil {
robotgo.KeyTap(*command.Key)
} else {
robotgo.KeyTap(*command.Key, *command.Alt...)
}
}
}
}
}