2015-07-10 02:33:46 +08:00
|
|
|
/*
|
2016-07-14 00:44:47 +08:00
|
|
|
Package keyboard contains the Gobot drivers for keyboard support.
|
2015-07-10 02:33:46 +08:00
|
|
|
|
|
|
|
Installing:
|
|
|
|
|
|
|
|
Then you can install the package with:
|
|
|
|
|
2023-06-05 00:36:55 +08:00
|
|
|
Please refer to the main [README.md](https://github.com/hybridgroup/gobot/blob/release/README.md)
|
2015-07-10 02:33:46 +08:00
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2023-05-20 20:25:21 +08:00
|
|
|
"gobot.io/x/gobot/v2"
|
|
|
|
"gobot.io/x/gobot/v2/platforms/keyboard"
|
2015-07-10 02:33:46 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2016-09-26 03:27:37 +08:00
|
|
|
keys := keyboard.NewDriver()
|
2015-07-10 02:33:46 +08:00
|
|
|
|
|
|
|
work := func() {
|
2024-02-11 22:34:50 +08:00
|
|
|
_ = 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,
|
|
|
|
)
|
|
|
|
|
2024-02-11 22:34:50 +08:00
|
|
|
if err := robot.Start(); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2015-07-10 02:33:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
For further information refer to keyboard README:
|
2024-02-13 22:58:31 +08:00
|
|
|
https://github.com/hybridgroup/gobot/blob/release/platforms/keyboard/README.md
|
2015-07-10 02:33:46 +08:00
|
|
|
*/
|
2023-05-20 20:25:21 +08:00
|
|
|
package keyboard // import "gobot.io/x/gobot/v2/platforms/keyboard"
|