forked from achushu/CH57x-keyboard-mapper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
68 lines (55 loc) · 1.24 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"fmt"
"os"
"github.com/achushu/hid"
)
var (
Custom = []Sequence{
{NOMOD, N1}, {NOMOD, N2}, {NOMOD, N3}, {NOMOD, N4},
{NOMOD, N5}, {NOMOD, N6}, {NOMOD, N7}, {NOMOD, N8},
{NOMOD, N9}, {NOMOD, N0}, {NOMOD, MINUS}, {NOMOD, EQUAL},
{NOMOD, COMMA}, {NOMOD, SLASH}, {NOMOD, DOT},
{NOMOD, SCOLON}, {NOMOD, BSLASH}, {NOMOD, QUOTE},
}
)
func main() {
var err error
if !hid.Supported() {
fmt.Println("this platform / binary does not support HID")
os.Exit(1)
}
dev := SelectInterface()
if dev.Path == "" {
fmt.Printf("could not find the device interface")
os.Exit(2)
}
kbd, err := NewKeyboard(dev)
if err != nil {
fmt.Printf("error opening device %s\n%s\n", dev.Path, err)
os.Exit(2)
}
defer kbd.Close()
fmt.Println("connected to keyboard")
err = kbd.SendHello()
if err != nil {
fmt.Println("error writing to device:", err)
}
fmt.Println("sent hello")
kbd.BindMapping(MapKeys(Custom))
fmt.Println("done!")
}
func SelectInterface() hid.DeviceInfo {
var info hid.DeviceInfo
devices := hid.Enumerate(VENDOR_ID, PRODUCT_ID)
if len(devices) == 0 {
fmt.Println("no macro keyboard detected")
os.Exit(1)
}
for _, d := range devices {
if d.Interface == INTERFACE {
return d
}
}
return info
}