From 4b990bcc82ebda781d9697f4f5e3eb082939af8a Mon Sep 17 00:00:00 2001 From: Dmitry Lyukov Date: Sat, 26 Mar 2016 04:28:29 +0300 Subject: [PATCH] Implemented GetKeymapFromOutput --- src/main.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main.go b/src/main.go index 9202d6f..bd3388c 100644 --- a/src/main.go +++ b/src/main.go @@ -7,6 +7,7 @@ import ( "os/exec" "regexp" "strconv" + "strings" "time" ) @@ -32,7 +33,17 @@ func GetKeymapOutput() []byte { // Return map with keymap from text func GetKeymapFromOutput(buf []byte) map[uint8]string { - return make(map[uint8]string) + const KEY_NUM_STRING_RE = "\\d+[ ]*=[ ]*\\S+" + re := regexp.MustCompile(KEY_NUM_STRING_RE) + resByte := re.FindAll(buf, -1) + keyMap := make(map[uint8]string) + for _, line := range resByte { + lineSpitted := strings.Split(string(line), " ") + if key, err := strconv.Atoi(lineSpitted[0]); err == nil { + keyMap[uint8(key)] = lineSpitted[2] + } + } + return keyMap } // Extract pressed keys from bufer buf