-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathkey_holder.go
More file actions
46 lines (35 loc) · 811 Bytes
/
key_holder.go
File metadata and controls
46 lines (35 loc) · 811 Bytes
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 (
"github.com/micmonay/keybd_event"
"runtime"
"time"
)
type KeyHolder struct {
left keybd_event.KeyBonding
right keybd_event.KeyBonding
}
func NewKeyHolder() *KeyHolder {
controller := &KeyHolder{}
left, errLeft := keybd_event.NewKeyBonding()
right, errRight := keybd_event.NewKeyBonding()
if errLeft != nil {
panic(errLeft)
} else if errRight != nil {
panic(errRight)
}
controller.left = left
controller.right = right
// For linux, it is very important wait 2 seconds
if runtime.GOOS == "linux" {
time.Sleep(2 * time.Second)
}
controller.left.SetKeys(keybd_event.VK_LEFT)
controller.right.SetKeys(keybd_event.VK_RIGHT)
return controller
}
func (c *KeyHolder) PressLeft() {
c.left.Launching()
}
func (c *KeyHolder) PressRight() {
c.right.Launching()
}