adding reader
This commit is contained in:
parent
bff21a4803
commit
580350f08d
1
ai/main.go
Normal file
1
ai/main.go
Normal file
|
@ -0,0 +1 @@
|
|||
package ai
|
28
main.go
28
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
|
||||
|
|
Loading…
Reference in a new issue