modulepackage
0.0.0-20230915094254-f1fe564743c3
Repository: https://github.com/n4x2/keyboard.git
Documentation: pkg.go.dev
# README
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 with a blocking GetKey()
function:
package main
import (
"fmt"
"github.com/eiannone/keyboard"
)
func main() {
if err := keyboard.Open(); err != nil {
panic(err)
}
defer func() {
_ = keyboard.Close()
}()
fmt.Println("Press ESC to quit")
for {
char, key, err := keyboard.GetKey()
if err != nil {
panic(err)
}
fmt.Printf("You pressed: rune %q, key %X\r\n", char, key)
if key == keyboard.KeyEsc {
break
}
}
}
Example of getting a series of keystrokes using a channel:
package main
import (
"fmt"
"github.com/eiannone/keyboard"
)
func main() {
keysEvents, err := keyboard.GetKeys(10)
if err != nil {
panic(err)
}
defer func() {
_ = keyboard.Close()
}()
fmt.Println("Press ESC to quit")
for {
event := <-keysEvents
if event.Err != nil {
panic(event.Err)
}
fmt.Printf("You pressed: rune %q, key %X\r\n", event.Rune, event.Key)
if event.Key == keyboard.KeyEsc {
break
}
}
}
# Functions
Should be called after successful initialization when functionality isn't required anymore.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Constants
Key constants, see GetKey() function.
Key constants, see GetKey() function.
Key constants, see GetKey() function.
Key constants, see GetKey() function.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Key constants, see GetKey() function.
Key constants, see GetKey() function.
No description provided by the author
No description provided by the author
Key constants, see GetKey() function.
Key constants, see GetKey() function.
Key constants, see GetKey() function.
Key constants, see GetKey() function.
Key constants, see GetKey() function.
Key constants, see GetKey() function.
Key constants, see GetKey() function.
Key constants, see GetKey() function.
Key constants, see GetKey() function.
Key constants, see GetKey() function.
Key constants, see GetKey() function.
Key constants, see GetKey() function.
Key constants, see GetKey() function.
Key constants, see GetKey() function.
Key constants, see GetKey() function.
Key constants, see GetKey() function.
No description provided by the author
No description provided by the author
# Type aliases
No description provided by the author