37 lines
585 B
Go
37 lines
585 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(keyboard.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()
|
|
}
|