hybridgroup.gobot/platforms/keyboard
deadprogram 80cb23de32 core: update Keyboard platform to simply return error
Signed-off-by: deadprogram <ron@hybridgroup.com>
2016-11-07 21:29:51 +01:00
..
LICENSE misc: update all LICENSE files for current year 2016-08-27 13:12:47 +02:00
README.md docs: remove Master unless needed for less code 2016-10-18 21:37:10 +02:00
doc.go docs: remove Master unless needed for less code 2016-10-18 21:37:10 +02:00
keyboard.go core: update Keyboard platform to simply return error 2016-11-07 21:29:51 +01:00
keyboard_driver.go core: update Keyboard platform to simply return error 2016-11-07 21:29:51 +01:00
keyboard_driver_test.go core: update Keyboard platform to simply return error 2016-11-07 21:29:51 +01:00
keyboard_test.go tests: complete move of test interfaces into the test files where they belong 2016-08-27 11:56:01 +02:00

README.md

Keyboard

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

How to Install

go get github.com/hybridgroup/gobot && go install github.com/hybridgroup/gobot/platforms/keyboard

How to Use

Example parsing key events

package main

import (
	"fmt"

	"github.com/hybridgroup/gobot"
	"github.com/hybridgroup/gobot/platforms/keyboard"
)

func main() {
	keys := keyboard.NewDriver("keyboard")

	work := func() {
		gobot.On(keys.Event("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()
}