Skip to content

Commit 4d95da6

Browse files
committed
update sleep
add keytap
1 parent 850428c commit 4d95da6

File tree

3 files changed

+37
-11
lines changed

3 files changed

+37
-11
lines changed

README.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,15 @@
22

33
## Mouse
44
type: mouse
5-
button: [left, center, right, wheelDown, wheelUp, wheelLeft, wheelRight]
5+
button: [left, center, right, wheelDown, wheelUp, wheelLeft, wheelRight]
6+
7+
## KeyTap
8+
type: keytap
9+
key: string
10+
alt: [backspace, delete, enter, tab, esc, escape, up, down, right, left, home, end, pageup, pagedown, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, cmd, lcmd, rcmd, alt, lalt, ralt, ctrl, lctrl, rctrl, control, shift, lshift, rshift, capslock, space, print, printscreen, insert, menu]
11+
12+
## Sleep
13+
type: sleep
14+
key: string
15+
minSleep: int64
16+
maxSleep: int64

main.go

+15-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ type Config struct {
2222
MaxX *int `yaml:"maxX"`
2323
MaxY *int `yaml:"maxY"`
2424
Button *string
25-
Duration *int64
25+
MinSleep *int64 `yaml:"minSleep"`
26+
MaxSleep *int64 `yaml:"maxSleep"`
27+
Key *string
28+
Alt *[]interface{}
2629
}
2730
}
2831

@@ -55,10 +58,18 @@ func main() {
5558
panic(fmt.Sprintf("Invalid move configuration: %+v", command))
5659
}
5760
case "click":
58-
robotgo.Click(command.Button)
61+
robotgo.Click(*command.Button)
5962
case "sleep":
60-
fmt.Printf("Sleeping for %d milliseconds.", command.Duration)
61-
time.Sleep(time.Duration(*command.Duration) * time.Millisecond)
63+
sleepTime := rand.Int63n(*command.MaxSleep-*command.MinSleep) + *command.MinSleep
64+
fmt.Printf("Sleeping for %d milliseconds.", sleepTime)
65+
time.Sleep(time.Duration(sleepTime) * time.Millisecond)
66+
case "keytap":
67+
if command.Alt == nil {
68+
robotgo.KeyTap(*command.Key)
69+
} else {
70+
robotgo.KeyTap(*command.Key, *command.Alt...)
71+
}
72+
6273
}
6374
}
6475
}

script.yaml

+10-6
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ commands:
44
minY: 200
55
maxX: 400
66
maxY: 400
7+
- type: click
8+
button: left
9+
- type: keytap
10+
key: a
11+
- type: keytap
12+
key: s
13+
alt:
14+
- cmd
715
- type: sleep
8-
duration: 5000
9-
10-
# - type: sleep
11-
# duration: 3000
12-
# - type: click
13-
# button: right
16+
minSleep: 4000
17+
maxSleep: 7000

0 commit comments

Comments
 (0)