qmp-testing-suite/golang-producer-consumer/vendor/github.com/eiannone/keyboard
bel 3997f8ce6e push 2021-09-12 21:58:04 -06:00
..
AUTHORS push 2021-09-12 21:58:04 -06:00
LICENSE push 2021-09-12 21:58:04 -06:00
README.md push 2021-09-12 21:58:04 -06:00
keyboard.go push 2021-09-12 21:58:04 -06:00
keyboard_common.go push 2021-09-12 21:58:04 -06:00
keyboard_windows.go push 2021-09-12 21:58:04 -06:00
syscalls.go push 2021-09-12 21:58:04 -06:00
syscalls_linux.go push 2021-09-12 21:58:04 -06:00
terminfo.go push 2021-09-12 21:58:04 -06:00

README.md

Keyboard

Simple library to listen for keystrokes from the keyboard

The code is inspired by termbox-go library.

Installation

Install and update this go package with go get -u github.com/eiannone/keyboard

Usage

Example of getting a single keystroke:

char, _, err := keyboard.GetSingleKey()
if (err != nil) {
    panic(err)
}
fmt.Printf("You pressed: %q\r\n", char)

Example of getting a series of keystrokes:

package main

import (
	"fmt"
	"github.com/eiannone/keyboard"
)

func main() {	
	err := keyboard.Open()
	if err != nil {
		panic(err)
	}
	defer keyboard.Close()

	fmt.Println("Press ESC to quit")
	for {
		char, key, err := keyboard.GetKey()
		if (err != nil) {
			panic(err)
		} else if (key == keyboard.KeyEsc) {
			break
		}
		fmt.Printf("You pressed: %q\r\n", char)
	}	
}