README ¶
Keyboard
This module implements support for keyboard events, wrapping the stty
utility.
How to Install
go get gobot.io/x/gobot && go install gobot.io/x/gobot/platforms/keyboard
How to Use
Example parsing key events
package main
import (
"fmt"
"gobot.io/x/gobot"
"gobot.io/x/gobot/platforms/keyboard"
)
func main() {
keys := keyboard.NewDriver()
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,
)
robot.Start()
}
Documentation ¶
Overview ¶
Package keyboard contains the Gobot drivers for keyboard support.
Installing:
Then you can install the package with:
go get gobot.io/x/gobot && go install gobot.io/x/gobot/platforms/keyboard
Example:
package main import ( "fmt" "gobot.io/x/gobot" "gobot.io/x/gobot/platforms/keyboard" ) func main() { keys := keyboard.NewDriver() 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, ) robot.Start() }
For further information refer to keyboard README: https://github.com/hybridgroup/gobot/blob/master/platforms/keyboard/README.md
Index ¶
Constants ¶
View Source
const ( Tilde = iota + 96 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z )
View Source
const ( Escape = 27 Spacebar = 32 )
View Source
const ( Zero = iota + 48 One Two Three Four Five Six Seven Eight Nine )
View Source
const ( ArrowUp = iota + 65 ArrowDown ArrowRight ArrowLeft )
View Source
const (
// Key board event
Key = "key"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Driver ¶ added in v1.0.0
Driver is gobot software device to the keyboard
func (*Driver) Connection ¶ added in v1.0.0
func (k *Driver) Connection() gobot.Connection
Connection returns the Driver Connection
Click to show internal directories.
Click to hide internal directories.