-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
key.go
50 lines (43 loc) · 789 Bytes
/
key.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
// Copyright (c) 2023 Joshua Rich <[email protected]>
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
package gokbd
// #cgo pkg-config: libevdev
// #include <libevdev/libevdev.h>
// #include <libevdev/libevdev-uinput.h>
import "C"
type key struct {
keyType, keyCode, value int
}
func keyPress(c int) *key {
return &key{
keyType: C.EV_KEY,
keyCode: c,
value: 1,
}
}
func keyRelease(c int) *key {
return &key{
keyType: C.EV_KEY,
keyCode: c,
value: 0,
}
}
func keySync() *key {
return &key{
keyType: C.EV_SYN,
keyCode: C.SYN_REPORT,
value: 0,
}
}
func keySequence(keys ...*key) <-chan *key {
out := make(chan *key)
go func() {
for _, n := range keys {
out <- n
}
close(out)
}()
return out
}