2015-07-10 02:33:46 +08:00
|
|
|
# Keyboard
|
|
|
|
|
|
|
|
This module implements support for keyboard events, wrapping the `stty` utility.
|
|
|
|
|
|
|
|
## How to Install
|
|
|
|
|
|
|
|
```
|
2016-05-25 01:34:22 +08:00
|
|
|
go get github.com/hybridgroup/gobot && go install github.com/hybridgroup/gobot/platforms/keyboard
|
2015-07-10 02:33:46 +08:00
|
|
|
```
|
|
|
|
|
|
|
|
## How to Use
|
|
|
|
|
|
|
|
Example parsing key events
|
|
|
|
|
|
|
|
```go
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/hybridgroup/gobot"
|
|
|
|
"github.com/hybridgroup/gobot/platforms/keyboard"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2016-12-01 06:32:20 +08:00
|
|
|
keys := keyboard.NewDriver()
|
2015-07-10 02:33:46 +08:00
|
|
|
|
|
|
|
work := func() {
|
2016-12-01 06:32:20 +08:00
|
|
|
keys.On(keyboard.Key, func(data interface{}) {
|
2015-07-10 02:33:46 +08:00
|
|
|
key := data.(keyboard.KeyEvent)
|
|
|
|
|
|
|
|
if key.Key == keyboard.A {
|
|
|
|
fmt.Println("A pressed!")
|
|
|
|
} else {
|
|
|
|
fmt.Println("keyboard event!", key, key.Char)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
robot := gobot.NewRobot("keyboardbot",
|
|
|
|
[]gobot.Connection{},
|
|
|
|
[]gobot.Device{keys},
|
|
|
|
work,
|
|
|
|
)
|
|
|
|
|
2016-10-19 03:37:10 +08:00
|
|
|
robot.Start()
|
2015-07-10 02:33:46 +08:00
|
|
|
}
|
|
|
|
```
|