From 2697df4352415c72a31555e97536d6f6b70921c3 Mon Sep 17 00:00:00 2001 From: lordwelch Date: Wed, 24 Jan 2018 14:43:33 -0800 Subject: [PATCH] Fix return keymap to 0 No longer attempts to change keymap when there is only one Fixed typo in keymap --- hid/tengwar-u.json | 4 ++-- main.go | 29 ++++++++++++++++------------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/hid/tengwar-u.json b/hid/tengwar-u.json index bfb5462..7d3fcb1 100644 --- a/hid/tengwar-u.json +++ b/hid/tengwar-u.json @@ -81,11 +81,11 @@ }, "": { "modifier": ["LSHIFT"], - "decimal": 46 + "decimal": 45 }, "‍": { "modifier": ["LSHIFT"], - "decimal": 45 + "decimal": 46 }, "": { "modifier": ["NONE"], diff --git a/main.go b/main.go index 0849f2a..23ad917 100644 --- a/main.go +++ b/main.go @@ -47,23 +47,26 @@ func Hold(press [8]byte, file io.Writer) { } func keymapto0(args Args, hidg0 *os.File, currentKeyMap *int) { - - for i := 0; i <= len(args.ORDER)-(*currentKeyMap+1); i++ { - Press([8]byte{LALT, 0x00, 0x39, 0x00, 0x00, 0x00, 0x00, 0x00}, hidg0) + if len(args.ORDER) > 1 { + for i := 0; i < len(args.ORDER)-(*currentKeyMap); i++ { + Press([8]byte{LALT, 0x00, 0x39, 0x00, 0x00, 0x00, 0x00, 0x00}, hidg0) + } } } func changeKeymap(r rune, keys map[string]Keys, args Args, hidg0 *os.File, currentKeyMap *int) { - for i := 0; i < len(args.ORDER); i++ { - if keys[args.ORDER[(*currentKeyMap)]][string(r)].Decimal == 0 { - Press([8]byte{LALT, 0x00, 0x39, 0x00, 0x00, 0x00, 0x00, 0x00}, hidg0) - if *currentKeyMap == len(args.ORDER)-1 { - *currentKeyMap = 0 - } else { - *currentKeyMap++ - } - if i == len(args.ORDER)-1 { - fmt.Println("key not in keymap: " + string(r)) + if len(args.ORDER) > 1 { + for i := 0; i < len(args.ORDER); i++ { + if keys[args.ORDER[(*currentKeyMap)]][string(r)].Decimal == 0 { + Press([8]byte{LALT, 0x00, 0x39, 0x00, 0x00, 0x00, 0x00, 0x00}, hidg0) + if *currentKeyMap == len(args.ORDER)-1 { + *currentKeyMap = 0 + } else { + *currentKeyMap++ + } + if i == len(args.ORDER)-1 { + fmt.Println("key not in keymap: " + string(r)) + } } } }