hybridgroup.gobot/platforms/keyboard
Thomas Kohler f5d8d5c601
all(style) : fix linter issues for errcheck, ineffassign, unused and fix errors (#950)
2023-06-12 19:51:25 +02: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 Build(v2): revert move to v2 subfolder (#932) 2023-05-29 19:23:28 +02: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 Build(v2): revert move to v2 subfolder (#932) 2023-05-29 19:23:28 +02:00
keyboard_test.go Build(v2): revert move to v2 subfolder (#932) 2023-05-29 19:23:28 +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()
}