hybridgroup.gobot/platforms/keyboard
deadprogram f225a66db9 docs: correct installation instructions to match latest versions
Signed-off-by: deadprogram <ron@hybridgroup.com>
2017-06-15 14:04:08 +02:00
..
LICENSE
README.md docs: correct installation instructions to match latest versions 2017-06-15 14:04:08 +02:00
doc.go
keyboard.go
keyboard_driver.go
keyboard_driver_test.go
keyboard_test.go

README.md

Keyboard

This module implements support for keyboard events, wrapping the stty utility.

How to Install

go get -d -u gobot.io/x/gobot/...

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