-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
52 lines (40 loc) · 1.1 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
package main
import (
"flag"
"time"
"github.com/go-vgo/robotgo"
)
func checkLoop(screenWidth, mouseX, activationMargin int) string {
if mouseX+activationMargin > screenWidth {
return "left"
} else if mouseX-activationMargin < 0 {
return "right"
}
return ""
}
func run(activationMargin, jumpDelta *int) {
screenWidth, _ := robotgo.GetScreenSize()
mouseX, mouseY := robotgo.GetMousePos()
loop := checkLoop(screenWidth, mouseX, *activationMargin)
switch loop {
case "left":
robotgo.MoveMouse(*activationMargin+*jumpDelta, mouseY)
case "right":
robotgo.MoveMouse(screenWidth-(*activationMargin+*jumpDelta), mouseY)
}
}
func main() {
activationMargin := flag.Int("activationMargin", 10, "Jump activation margin")
jumpDelta := flag.Int("jumpDelta", 1, "Jump delta distance from activation margin")
hz := flag.Int("hz", 50, "Pointer position check frequency")
d := flag.Bool("d", false, "Daemonize and return control")
flag.Parse()
if *d {
for {
run(activationMargin, jumpDelta)
time.Sleep(time.Duration(*hz) * time.Millisecond)
}
} else {
run(activationMargin, jumpDelta)
}
}