-
Notifications
You must be signed in to change notification settings - Fork 4
/
actions.go
59 lines (48 loc) · 863 Bytes
/
actions.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
package main
import (
"fmt"
"github.com/hagen1778/macros/keyboard"
"time"
)
type step map[string]string
func (s step) convertToAction() (a runner, err error) {
for key, value := range s {
switch key {
case "sleep":
var dur time.Duration
dur, err = time.ParseDuration(value)
if err != nil {
return
}
a = sleep{dur}
case "print":
a = print{value}
case "press":
a = press{value}
default:
err = fmt.Errorf("Wrong rule type")
}
}
return
}
type runner interface {
Run(d *keyboard.InputDevice)
}
type press struct {
value string
}
type print struct {
value string
}
type sleep struct {
value time.Duration
}
func (a press) Run(d *keyboard.InputDevice) {
d.Press(a.value)
}
func (a print) Run(d *keyboard.InputDevice) {
d.Print(a.value)
}
func (a sleep) Run(d *keyboard.InputDevice) {
time.Sleep(a.value)
}