hybridgroup.gobot/examples/keyboard.go

37 lines
590 B
Go
Raw Normal View History

2015-07-10 02:33:46 +08:00
package main
import (
"fmt"
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/platforms/keyboard"
)
func main() {
gbot := gobot.NewGobot()
keys := keyboard.NewKeyboardDriver("keyboard")
work := func() {
keys.On(keys.Event("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,
)
gbot.AddRobot(robot)
gbot.Start()
}