hybridgroup.gobot/examples/keyboard.go

33 lines
494 B
Go
Raw Normal View History

2015-07-10 02:33:46 +08:00
package main
import (
"fmt"
"gobot.io/x/gobot"
"gobot.io/x/gobot/platforms/keyboard"
2015-07-10 02:33:46 +08:00
)
func main() {
keys := keyboard.NewDriver()
2015-07-10 02:33:46 +08:00
work := func() {
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,
)
robot.Start()
2015-07-10 02:33:46 +08:00
}