gobot.io/x/gobot@v1.16.0/platforms/keyboard/README.md (about)

     1  # Keyboard
     2  
     3  This module implements support for keyboard events, wrapping the `stty` utility.
     4  
     5  ## How to Install
     6  
     7  ```
     8  go get -d -u gobot.io/x/gobot/...
     9  ```
    10  
    11  ## How to Use
    12  
    13  Example parsing key events
    14  
    15  ```go
    16  package main
    17  
    18  import (
    19  	"fmt"
    20  
    21  	"gobot.io/x/gobot"
    22  	"gobot.io/x/gobot/platforms/keyboard"
    23  )
    24  
    25  func main() {
    26  	keys := keyboard.NewDriver()
    27  
    28  	work := func() {
    29  		keys.On(keyboard.Key, func(data interface{}) {
    30  			key := data.(keyboard.KeyEvent)
    31  
    32  			if key.Key == keyboard.A {
    33  				fmt.Println("A pressed!")
    34  			} else {
    35  				fmt.Println("keyboard event!", key, key.Char)
    36  			}
    37  		})
    38  	}
    39  
    40  	robot := gobot.NewRobot("keyboardbot",
    41  		[]gobot.Connection{},
    42  		[]gobot.Device{keys},
    43  		work,
    44  	)
    45  
    46  	robot.Start()
    47  }
    48  ```