hybridgroup.gobot/platforms/keyboard
Thomas Kohler 7f78edefcd
lint(all): fix issues of errorlint etc (#1037)
2023-11-15 20:51:52 +01:00
..
LICENSE Build(v2): revert move to v2 subfolder (#932) 2023-05-29 19:23:28 +02:00
README.md core(build): CLI removed (#946) 2023-06-04 18:36:55 +02:00
doc.go core(build): CLI removed (#946) 2023-06-04 18:36:55 +02:00
keyboard.go lint(all): fix issues of errorlint etc (#1037) 2023-11-15 20:51:52 +01:00
keyboard_driver.go all(style) : fix linter issues for errcheck, ineffassign, unused and fix errors (#950) 2023-06-12 19:51:25 +02:00
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,
  )

  robot.Start()
}