2015-07-10 02:33:46 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2016-12-08 20:24:03 +08:00
|
|
|
"gobot.io/x/gobot"
|
|
|
|
"gobot.io/x/gobot/platforms/keyboard"
|
2015-07-10 02:33:46 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2016-10-03 22:58:43 +08:00
|
|
|
keys := keyboard.NewDriver()
|
2015-07-10 02:33:46 +08:00
|
|
|
|
|
|
|
work := func() {
|
2016-09-01 18:17:43 +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:08:25 +08:00
|
|
|
robot.Start()
|
2015-07-10 02:33:46 +08:00
|
|
|
}
|