keyboard

package
v0.0.0-...-59c18d7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 20, 2015 License: Apache-2.0, Apache-2.0 Imports: 4 Imported by: 0

README

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/ardrone

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

Documentation

Overview

Packge keyboard contains the Gobot drivers for keyboard support.

Installing:

Then you can install the package with:

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

Example:

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

For further information refer to keyboard README: https://github.com/hybridgroup/gobot/blob/master/platforms/keyboard/README.md

Index

Constants

View Source
const (
	Tilde = iota + 96
	A
	B
	C
	D
	E
	F
	G
	H
	I
	J
	K
	L
	M
	N
	O
	P
	Q
	R
	S
	T
	U
	V
	W
	X
	Y
	Z
)
View Source
const (
	Escape   = 27
	Spacebar = 32
)
View Source
const (
	Zero = iota + 48
	One
	Two
	Three
	Four
	Five
	Six
	Seven
	Eight
	Nine
)
View Source
const (
	ArrowUp = iota + 65
	ArrowDown
	ArrowRight
	ArrowLeft
)

Variables

This section is empty.

Functions

This section is empty.

Types

type KeyEvent

type KeyEvent struct {
	Bytes bytes
	Key   int
	Char  string
}

func Parse

func Parse(input bytes) KeyEvent

type KeyboardDriver

type KeyboardDriver struct {
	gobot.Eventer
	// contains filtered or unexported fields
}

func NewKeyboardDriver

func NewKeyboardDriver(name string) *KeyboardDriver

func (*KeyboardDriver) Connection

func (k *KeyboardDriver) Connection() gobot.Connection

func (*KeyboardDriver) Halt

func (k *KeyboardDriver) Halt() (errs []error)

Halt stops camera driver

func (*KeyboardDriver) Name

func (k *KeyboardDriver) Name() string

func (*KeyboardDriver) Start

func (k *KeyboardDriver) Start() (errs []error)

Start initializes keyboard by grabbing key events as they come in and publishing a key event

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL