Fix shortcut parsing and keymap list

This commit is contained in:
Timmy Welch 2024-04-17 17:30:19 -07:00
parent 572af746fa
commit d70c691ac7
2 changed files with 6 additions and 6 deletions

View File

@ -3,6 +3,7 @@ package hid
var ( var (
StandardKeys = map[string]byte{ StandardKeys = map[string]byte{
"␀": 0x00, "␀": 0x00,
"": 0x00,
"a": 0x04, "a": 0x04,
"A": 0x04, "A": 0x04,
"b": 0x05, "b": 0x05,

11
main.go
View File

@ -1,7 +1,6 @@
package main package main
import ( import (
"errors"
"flag" "flag"
"fmt" "fmt"
"io" "io"
@ -32,14 +31,14 @@ func parse_shortcut(shortcut string) ([8]byte, error) {
) )
strs := strings.SplitN(strings.ToLower(shortcut), " ", 2) strs := strings.SplitN(strings.ToLower(shortcut), " ", 2)
if len(strs) > 1 { if len(strs) > 1 {
modifiers = strings.Split(strs[0], "|")
key = strings.TrimSpace(strs[1])
} else {
if contains(strs[0], hid.AllModifiers) { if contains(strs[0], hid.AllModifiers) {
modifiers = strings.Split(strs[0], "|") modifiers = strings.Split(strs[0], "|")
} else { } else {
key = strings.TrimSpace(strs[0]) key = strings.TrimSpace(strs[0])
} }
} else {
modifiers = strings.Split(strs[0], "|")
key = strings.TrimSpace(strs[1])
} }
for _, v := range modifiers { for _, v := range modifiers {
curModifier |= hid.Modifiers[strings.TrimSpace(v)] curModifier |= hid.Modifiers[strings.TrimSpace(v)]
@ -47,7 +46,7 @@ func parse_shortcut(shortcut string) ([8]byte, error) {
if id, ok := hid.StandardKeys[key]; ok { if id, ok := hid.StandardKeys[key]; ok {
curKey = id curKey = id
} else { } else {
return [8]byte{}, errors.New("Key not found") return [8]byte{}, fmt.Errorf("Key %q not found", key)
} }
return [8]byte{curModifier, 0x0, curKey}, nil return [8]byte{curModifier, 0x0, curKey}, nil
} }
@ -94,7 +93,7 @@ keymap:
for _, requestedKeymap := range flag.Args() { for _, requestedKeymap := range flag.Args() {
for _, dir := range dirs { for _, dir := range dirs {
if strings.HasPrefix(strings.ToLower(dir.Name()), strings.ToLower(requestedKeymap)) { if strings.HasPrefix(strings.ToLower(dir.Name()), strings.ToLower(requestedKeymap)) {
keymaps = append(keymaps, dir.Name()) keymaps = append(keymaps, strings.TrimSuffix(dir.Name(), ".json"))
break keymap break keymap
} }
} }