hybridgroup.gobot/platforms/keyboard
deadprogram 60fdeef5c5 docs: correct Keyboard README link
Signed-off-by: deadprogram <ron@hybridgroup.com>
2016-12-21 10:52:46 +01:00
..
LICENSE misc: update all LICENSE files for current year 2016-08-27 13:12:47 +02:00
README.md core: use canonical import domain of gobot.io for all code 2016-12-08 13:24:03 +01:00
doc.go docs: correct Keyboard README link 2016-12-21 10:52:46 +01:00
keyboard.go docs: Add missing godocs for keyboard platform 2016-11-30 23:32:20 +01:00
keyboard_driver.go core: use canonical import domain of gobot.io for all code 2016-12-08 13:24:03 +01:00
keyboard_driver_test.go core: use canonical import domain of gobot.io for all code 2016-12-08 13:24:03 +01:00
keyboard_test.go core: use canonical import domain of gobot.io for all code 2016-12-08 13:24:03 +01:00

README.md

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