/
keyboard.go
49 lines (43 loc) · 1.03 KB
/
keyboard.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
package draw
import "log"
const (
KeyFn = '\uF000'
KeyHome = KeyFn | 0x0D
KeyUp = KeyFn | 0x0E
KeyPageUp = KeyFn | 0xF
KeyPrint = KeyFn | 0x10
KeyLeft = KeyFn | 0x11
KeyRight = KeyFn | 0x12
KeyDown = 0x80
KeyView = 0x80
KeyPageDown = KeyFn | 0x13
KeyInsert = KeyFn | 0x14
KeyEnd = KeyFn | 0x18
KeyAlt = KeyFn | 0x15
KeyShift = KeyFn | 0x16
KeyCtl = KeyFn | 0x17
KeyBackspace = 0x08
KeyDelete = 0x7F
KeyEscape = 0x1b
KeyEOF = 0x04
KeyCmd = 0xF100
)
// Keyboardctl is the source of keyboard events.
type Keyboardctl struct {
C <-chan rune // Channel on which keyboard characters are delivered.
}
// InitKeyboard connects to the keyboard and returns a Keyboardctl to listen to it.
func (d *Display) InitKeyboard() *Keyboardctl {
ch := make(chan rune, 20)
go kbdproc(d, ch)
return &Keyboardctl{ch}
}
func kbdproc(d *Display, ch chan rune) {
for {
r, err := d.conn.ReadKbd()
if err != nil {
log.Fatal("readkbd: ", err)
}
ch <- r
}
}