-
Notifications
You must be signed in to change notification settings - Fork 0
/
clicker.go
46 lines (39 loc) · 853 Bytes
/
clicker.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
package main
import (
"math/rand"
"time"
"github.com/go-vgo/robotgo"
)
type Config struct {
ProcessTitle string `yaml:"process-title"`
Deactivate string `yaml:"deactivate"`
LeftClick ConfigClick `yaml:"left"`
RightClick ConfigClick `yaml:"right"`
}
type ConfigClick struct {
Deactivate string `yaml:"deactivate"`
Delay Delay `yaml:"delay"`
}
type Delay struct {
Value int `yaml:"value"`
Threshold int `yaml:"threshold"`
}
type Clicker struct {
delay Delay
running bool
button string
}
func (c *Clicker) activate() {
var delay int
lower := c.delay.Value - c.delay.Threshold
higher := c.delay.Value + c.delay.Threshold
diff := higher - lower
for {
if !c.running {
return
}
robotgo.Click(c.button)
delay = rand.Intn(diff) + lower
time.Sleep(time.Duration(delay) * time.Millisecond)
}
}