hybridgroup.gobot/examples/keyboard.go

37 lines
590 B
Go

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{}) {
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()
}