hybridgroup.gobot/platforms/keyboard
deadprogram 628a087a0f keyboard: increase test coverage
Signed-off-by: deadprogram <ron@hybridgroup.com>
2017-04-06 10:49:34 +02:00
..
LICENSE license: update license year to include 2017 2017-01-02 22:25:17 +01: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 keyboard: use new improved default namer to avoid API conflicts 2017-02-02 16:25:43 +01:00
keyboard_driver_test.go keyboard: increase test coverage 2017-04-06 10:49:34 +02: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()
}