hybridgroup.gobot/platforms/keyboard
Thomas Kohler 27d0b2164c
doc: update links to release or tagged branch (#1069)
2024-02-13 15:58:31 +01:00
..
LICENSE
README.md examples: fix missing checks of return values (#1060) 2024-02-11 15:34:50 +01:00
doc.go doc: update links to release or tagged branch (#1069) 2024-02-13 15:58:31 +01:00
keyboard.go lint(all): fix issues of errorlint etc (#1037) 2023-11-15 20:51:52 +01:00
keyboard_driver.go
keyboard_driver_test.go lint(all): fix issues of errorlint etc (#1037) 2023-11-15 20:51:52 +01:00
keyboard_test.go test(all): switch to test package stretchr testify (#1006) 2023-10-20 10:27:09 +02:00

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