hybridgroup.gobot/platforms/keyboard
Thomas Kohler d2b01b99e0
examples: fix missing checks of return values (#1060)
2024-02-11 15:34:50 +01:00
..
LICENSE
README.md examples: fix missing checks of return values (#1060) 2024-02-11 15:34:50 +01:00
doc.go examples: fix missing checks of return values (#1060) 2024-02-11 15:34:50 +01:00
keyboard.go
keyboard_driver.go
keyboard_driver_test.go
keyboard_test.go

README.md

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,
  )

  if err := robot.Start(); err != nil {
		panic(err)
	}
}