keyboard

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: May 10, 2017 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 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()
}

Documentation

Overview

Package keyboard contains the Gobot drivers for keyboard support.

Installing:

Then you can install the package with:

go get gobot.io/x/gobot && go install gobot.io/x/gobot/platforms/keyboard

Example:

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

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
)
View Source
const (
	// Key board event
	Key = "key"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Driver added in v1.0.0

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

Driver is gobot software device to the keyboard

func NewDriver added in v1.0.0

func NewDriver() *Driver

NewDriver returns a new keyboard Driver.

func (*Driver) Connection added in v1.0.0

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

Connection returns the Driver Connection

func (*Driver) Halt added in v1.0.0

func (k *Driver) Halt() (err error)

Halt stops keyboard driver

func (*Driver) Name added in v1.0.0

func (k *Driver) Name() string

Name returns the Driver Name

func (*Driver) SetName added in v1.0.0

func (k *Driver) SetName(n string)

SetName sets the Driver Name

func (*Driver) Start added in v1.0.0

func (k *Driver) Start() (err error)

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

type KeyEvent

type KeyEvent struct {
	Bytes bytes
	Key   int
	Char  string
}

KeyEvent contains data about a keyboard event

func Parse

func Parse(input bytes) KeyEvent

Jump to

Keyboard shortcuts

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