Fix shortcut parsing and keymap list
This commit is contained in:
parent
572af746fa
commit
d70c691ac7
@ -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
11
main.go
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user