2015-07-09 11:33:46 -07:00
|
|
|
/*
|
2016-07-13 10:44:47 -06:00
|
|
|
Package keyboard contains the Gobot drivers for keyboard support.
|
2015-07-09 11:33:46 -07:00
|
|
|
|
|
|
|
Installing:
|
|
|
|
|
|
|
|
Then you can install the package with:
|
|
|
|
|
2023-06-04 18:36:55 +02:00
|
|
|
Please refer to the main [README.md](https://github.com/hybridgroup/gobot/blob/release/README.md)
|
2015-07-09 11:33:46 -07:00
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2023-05-20 14:25:21 +02:00
|
|
|
"gobot.io/x/gobot/v2"
|
|
|
|
"gobot.io/x/gobot/v2/platforms/keyboard"
|
2015-07-09 11:33:46 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2016-09-25 21:27:37 +02:00
|
|
|
keys := keyboard.NewDriver()
|
2015-07-09 11:33:46 -07:00
|
|
|
|
|
|
|
work := func() {
|
2016-11-30 23:32:20 +01:00
|
|
|
keys.On(keyboard.Key, func(data interface{}) {
|
2015-07-09 11:33:46 -07: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-11-30 23:32:20 +01:00
|
|
|
robot.Start()
|
2015-07-09 11:33:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
For further information refer to keyboard README:
|
2016-12-21 10:52:46 +01:00
|
|
|
https://github.com/hybridgroup/gobot/blob/master/platforms/keyboard/README.md
|
2015-07-09 11:33:46 -07:00
|
|
|
*/
|
2023-05-20 14:25:21 +02:00
|
|
|
package keyboard // import "gobot.io/x/gobot/v2/platforms/keyboard"
|