hybridgroup.gobot/platforms/keyboard
Damian Gryski a8ea32ce56 Fix misspellings 2016-07-13 10:44:47 -06:00
..
LICENSE add basic keyboard driver using stty 2015-07-09 11:41:33 -07:00
README.md [keyboard] Adds more test coverage and fixes README install instructions 2016-05-24 10:34:22 -07:00
doc.go Fix misspellings 2016-07-13 10:44:47 -06:00
keyboard.go Re-enable echo when restoring 2015-07-09 13:52:08 -07:00
keyboard_driver.go add basic keyboard driver using stty 2015-07-09 11:41:33 -07:00
keyboard_driver_test.go Refactor to use `gobottest` test helpers 2016-02-22 00:33:58 -05:00
keyboard_test.go [keyboard] Adds more test coverage and fixes README install instructions 2016-05-24 10:34:22 -07: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() {
	gbot := gobot.NewGobot()

	keys := keyboard.NewKeyboardDriver("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,
	)

	gbot.AddRobot(robot)

	gbot.Start()
}