keyboard

package
v2.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2024 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

Please refer to the main README.md

How to Use

Example parsing key events

package main

import (
  "fmt"

  "gobot.io/x/gobot/v2"
  "gobot.io/x/gobot/v2/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:

Please refer to the main [README.md](https://github.com/hybridgroup/gobot/blob/release/README.md)

Example:

package main

import (
	"fmt"

	"gobot.io/x/gobot/v2"
	"gobot.io/x/gobot/v2/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
	Hyphen   = 45
	Asterisk = 42
	Plus     = 43
	Slash    = 47
	Dot      = 46
)
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

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

Driver is gobot software device to the keyboard

func NewDriver

func NewDriver() *Driver

NewDriver returns a new keyboard Driver.

func (*Driver) Connection

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

Connection returns the Driver Connection

func (*Driver) Halt

func (k *Driver) Halt() error

Halt stops keyboard driver

func (*Driver) Name

func (k *Driver) Name() string

Name returns the Driver Name

func (*Driver) SetName

func (k *Driver) SetName(n string)

SetName sets the Driver Name

func (*Driver) Start

func (k *Driver) Start() 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