adding reader

This commit is contained in:
Christopher Talib 2019-12-12 13:42:35 +01:00
parent bff21a4803
commit 580350f08d
2 changed files with 24 additions and 5 deletions

1
ai/main.go Normal file
View file

@ -0,0 +1 @@
package ai

28
main.go
View file

@ -14,6 +14,16 @@ import (
"github.com/sirupsen/logrus"
)
var ()
type InputStreamMap struct {
events map[string]InputStream
}
type InputStream struct {
event utils.InputEvent
}
// KeyLogger is a wrapper around a file descriptor.
type KeyLogger struct {
fd *os.File
@ -101,6 +111,15 @@ func (k *KeyLogger) Close() error {
return k.fd.Close()
}
func output(input InputStream) {
res := []string{}
for {
if input.event.KeyString() != "" {
res = append(res, input.event.KeyString())
}
}
}
func main() {
fmt.Println("Your keyboard input will be here: ", getKeyboard())
// TODO
@ -115,16 +134,15 @@ func main() {
}
defer klog.Close()
events := klog.Read()
stream := InputStream{}
go output(stream)
for e := range events {
switch e.Type {
case utils.EvKey:
if e.KeyPress() {
logrus.Println("press key", e.KeyString())
}
if e.KeyRelease() {
logrus.Println("release key", e.KeyRelease())
stream.event = e
}
break