-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
92 lines (82 loc) · 2.01 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package main
import (
"fmt"
"unicode"
"github.com/androbility/adbi"
"github.com/eiannone/keyboard"
log "github.com/sirupsen/logrus"
)
func main() {
bindings := adbi.LoadConfigFile("$HOME/.keydroid", defaultBindings)
for {
adbi.WaitForAndroid()
err := Watch(bindings)
log.Error(err)
}
}
func Watch(keymap map[rune]adbi.Keyevent) error {
cmndr, err := adbi.New()
if err != nil {
return fmt.Errorf("error connecting to adb server: %s", err)
}
for {
ch, key, err := keyboard.GetSingleKey()
if err != nil {
log.Fatal(err)
}
// Ctrl key values return [0, uint16], so convert the uint16
// to a rune.
if ch == 0 {
ch = rune(key)
}
// Quit on q, Q, and Ctrl-C.
if (unicode.ToLower(ch) == 'q') || (ch == '\x03') {
cmndr.Quit()
}
// We need to lookup the key. Is it defined?
event, ok := keymap[ch]
if !ok {
continue
}
if err = cmndr.Signal(event); err != nil {
return err
}
}
}
// Default keybindings for keydroid.
var defaultBindings = `{
"keybindings": {
"\b": "KEYCODE_BACK",
"\t": "KEYCODE_TAB",
"\r": "KEYCODE_ENTER",
"\d": "KEYCODE_MOUSE_SCROLL_DOWN",
"\u": "KEYCODE_MOUSE_SCROLL_UP",
" ": "KEYCODE_SPACE",
"-": "KEYCODE_VOLUME_DOWN",
"=": "KEYCODE_VOLUME_UP",
"+": "KEYCODE_VOLUME_UP",
"1": "KEYCODE_TV_INPUT_HDMI_1",
"2": "KEYCODE_TV_INPUT_HDMI_2",
"3": "KEYCODE_TV_INPUT_HDMI_3",
"4": "KEYCODE_TV_INPUT_HDMI_4",
"a": "KEYCODE_ASSIST",
"b": "KEYCODE_BACK",
"c": "KEYCODE_DPAD_CENTER",
"f": "KEYCODE_MEDIA_FAST_FORWARD",
"h": "KEYCODE_DPAD_LEFT",
"i": "KEYCODE_TV_INPUT",
"j": "KEYCODE_DPAD_DOWN",
"k": "KEYCODE_DPAD_UP",
"l": "KEYCODE_DPAD_RIGHT",
"m": "KEYCODE_MUTE",
"o": "KEYCODE_HOME",
"p": "KEYCODE_MEDIA_PLAY_PAUSE",
"r": "KEYCODE_MEDIA_REWIND",
"s": "KEYCODE_MEDIA_STOP",
"S": "KEYCODE_SLEEP",
"t": "KEYCODE_TV_TIMER_PROGRAMMING",
"u": "KEYCODE_MENU",
"v": "KEYCODE_HELP",
"w": "KEYCODE_WAKEUP"
}}
`