From 580350f08de3bdda3d384c0ce6af04665aa8a7eb Mon Sep 17 00:00:00 2001 From: Christopher Talib Date: Thu, 12 Dec 2019 13:42:35 +0100 Subject: [PATCH] adding reader --- ai/main.go | 1 + main.go | 28 +++++++++++++++++++++++----- 2 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 ai/main.go diff --git a/ai/main.go b/ai/main.go new file mode 100644 index 0000000..3831891 --- /dev/null +++ b/ai/main.go @@ -0,0 +1 @@ +package ai diff --git a/main.go b/main.go index e6dc717..a75d79c 100644 --- a/main.go +++ b/main.go @@ -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