gobot: gobot.io/x/gobot/platforms/keyboard Index | Files

package keyboard

import "gobot.io/x/gobot/platforms/keyboard"

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

Package Files

doc.go keyboard.go keyboard_driver.go

Constants

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
)
const (
    Escape   = 27
    Spacebar = 32
)
const (
    Zero = iota + 48
    One
    Two
    Three
    Four
    Five
    Six
    Seven
    Eight
    Nine
)
const (
    ArrowUp = iota + 65
    ArrowDown
    ArrowRight
    ArrowLeft
)
const (
    // Key board event
    Key = "key"
)

type Driver Uses

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

Driver is gobot software device to the keyboard

func NewDriver Uses

func NewDriver() *Driver

NewDriver returns a new keyboard Driver.

func (*Driver) Connection Uses

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

Connection returns the Driver Connection

func (*Driver) Halt Uses

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

Halt stops keyboard driver

func (*Driver) Name Uses

func (k *Driver) Name() string

Name returns the Driver Name

func (*Driver) SetName Uses

func (k *Driver) SetName(n string)

SetName sets the Driver Name

func (*Driver) Start Uses

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 Uses

type KeyEvent struct {
    Bytes bytes
    Key   int
    Char  string
}

KeyEvent contains data about a keyboard event

func Parse Uses

func Parse(input bytes) KeyEvent

Package keyboard imports 4 packages (graph) and is imported by 1 packages. Updated 2018-11-10. Refresh now. Tools for package owners.