mirror of https://github.com/EasyDarwin/EasyDarwin
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
penggy
395fd53106
|
6 years ago | |
---|---|---|
.. | ||
AUTHORS | 6 years ago | |
LICENSE | 6 years ago | |
README.md | 6 years ago | |
keyboard.go | 6 years ago | |
keyboard_common.go | 6 years ago | |
keyboard_windows.go | 6 years ago | |
syscalls.go | 6 years ago | |
syscalls_linux.go | 6 years ago | |
terminfo.go | 6 years ago |
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)
}
}