Added basic dvorak and json keymaps

Load keymap files from cfg dir
Start work on main loop
This commit is contained in:
lordwelch 2017-11-06 15:00:44 -07:00
parent 34290e969c
commit 498eb465a8
5 changed files with 1400 additions and 104 deletions

377
blank_keymap Normal file
View File

@ -0,0 +1,377 @@
: {
"modifier": "00000000",
"key": 39
},
: {
"modifier": "00000000",
"key": 30
},
: {
"modifier": "00000000",
"key": 31
},
: {
"modifier": "00000000",
"key": 32
},
: {
"modifier": "00000000",
"key": 33
},
: {
"modifier": "00000000",
"key": 34
},
: {
"modifier": "00000000",
"key": 35
},
: {
"modifier": "00000000",
"key": 36
},
: {
"modifier": "00000000",
"key": 37
},
: {
"modifier": "00000000",
"key": 38
},
: {
"modifier": "00000000",
"key": 53
},
: {
"modifier": "00000000",
"key": 47
},
: {
"modifier": "00000000",
"key": 48
},
: {
"modifier": "00000000",
"key": 52
},
: {
"modifier": "00000000",
"key": 54
},
: {
"modifier": "00000000",
"key": 55
},
: {
"modifier": "00000000",
"key": 19
},
: {
"modifier": "00000000",
"key": 28
},
: {
"modifier": "00000000",
"key": 9
},
: {
"modifier": "00000000",
"key": 10
},
: {
"modifier": "00000000",
"key": 6
},
: {
"modifier": "00000000",
"key": 21
},
: {
"modifier": "00000000",
"key": 15
},
: {
"modifier": "00000000",
"key": 56
},
: {
"modifier": "00000000",
"key": 46
},
: {
"modifier": "00000000",
"key": 49
},
: {
"modifier": "00000000",
"key": 4
},
: {
"modifier": "00000000",
"key": 18
},
: {
"modifier": "00000000",
"key": 8
},
: {
"modifier": "00000000",
"key": 24
},
: {
"modifier": "00000000",
"key": 12
},
: {
"modifier": "00000000",
"key": 7
},
: {
"modifier": "00000000",
"key": 11
},
: {
"modifier": "00000000",
"key": 23
},
: {
"modifier": "00000000",
"key": 17
},
: {
"modifier": "00000000",
"key": 22
},
: {
"modifier": "00000000",
"key": 45
},
: {
"modifier": "00000000",
"key": 51
},
: {
"modifier": "00000000",
"key": 20
},
: {
"modifier": "00000000",
"key": 13
},
: {
"modifier": "00000000",
"key": 14
},
: {
"modifier": "00000000",
"key": 27
},
: {
"modifier": "00000000",
"key": 5
},
: {
"modifier": "00000000",
"key": 16
},
: {
"modifier": "00000000",
"key": 26
},
: {
"modifier": "00000000",
"key": 25
},
: {
"modifier": "00000000",
"key": 29
},
: {
"modifier": "00000010",
"key": 53
},
: {
"modifier": "00000010",
"key": 30
},
: {
"modifier": "00000010",
"key": 31
},
: {
"modifier": "00000010",
"key": 32
},
: {
"modifier": "00000010",
"key": 33
},
: {
"modifier": "00000010",
"key": 34
},
: {
"modifier": "00000010",
"key": 35
},
: {
"modifier": "00000010",
"key": 36
},
: {
"modifier": "00000010",
"key": 37
},
: {
"modifier": "00000010",
"key": 38
},
: {
"modifier": "00000010",
"key": 39
},
: {
"modifier": "00000010",
"key": 47
},
: {
"modifier": "00000010",
"key": 48
},
: {
"modifier": "00000010",
"key": 52
},
: {
"modifier": "00000010",
"key": 54
},
: {
"modifier": "00000010",
"key": 55
},
: {
"modifier": "00000010",
"key": 19
},
: {
"modifier": "00000010",
"key": 28
},
: {
"modifier": "00000010",
"key": 9
},
: {
"modifier": "00000010",
"key": 10
},
: {
"modifier": "00000010",
"key": 6
},
: {
"modifier": "00000010",
"key": 21
},
: {
"modifier": "00000010",
"key": 15
},
: {
"modifier": "00000010",
"key": 56
},
: {
"modifier": "00000010",
"key": 46
},
: {
"modifier": "00000010",
"key": 49
},
: {
"modifier": "00000010",
"key": 4
},
: {
"modifier": "00000010",
"key": 18
},
: {
"modifier": "00000010",
"key": 8
},
: {
"modifier": "00000010",
"key": 24
},
: {
"modifier": "00000010",
"key": 12
},
: {
"modifier": "00000010",
"key": 7
},
: {
"modifier": "00000010",
"key": 11
},
: {
"modifier": "00000010",
"key": 23
},
: {
"modifier": "00000010",
"key": 17
},
: {
"modifier": "00000010",
"key": 22
},
: {
"modifier": "00000010",
"key": 45
},
: {
"modifier": "00000010",
"key": 51
},
: {
"modifier": "00000010",
"key": 20
},
: {
"modifier": "00000010",
"key": 13
},
: {
"modifier": "00000010",
"key": 14
},
: {
"modifier": "00000010",
"key": 27
},
: {
"modifier": "00000010",
"key": 5
},
: {
"modifier": "00000010",
"key": 16
},
: {
"modifier": "00000010",
"key": 26
},
: {
"modifier": "00000010",
"key": 25
},
: {
"modifier": "00000010",
"key": 29
}

472
dvorak.json Normal file
View File

@ -0,0 +1,472 @@
[
{
"key": "0",
"modifier": "00000000",
"decimal": 53
},
{
"key": "1",
"modifier": "00000000",
"decimal": 30
},
{
"key": "2",
"modifier": "00000000",
"decimal": 31
},
{
"key": "3",
"modifier": "00000000",
"decimal": 32
},
{
"key": "4",
"modifier": "00000000",
"decimal": 33
},
{
"key": "5",
"modifier": "00000000",
"decimal": 34
},
{
"key": "6",
"modifier": "00000000",
"decimal": 35
},
{
"key": "7",
"modifier": "00000000",
"decimal": 36
},
{
"key": "8",
"modifier": "00000000",
"decimal": 37
},
{
"key": "9",
"modifier": "00000000",
"decimal": 38
},
{
"key": "`",
"modifier": "00000000",
"decimal": 39
},
{
"key": "-",
"modifier": "00000000",
"decimal": 47
},
{
"key": "=",
"modifier": "00000000",
"decimal": 48
},
{
"key": "q",
"modifier": "00000000",
"decimal": 52
},
{
"key": "w",
"modifier": "00000000",
"decimal": 54
},
{
"key": "e",
"modifier": "00000000",
"decimal": 55
},
{
"key": "r",
"modifier": "00000000",
"decimal": 19
},
{
"key": "t",
"modifier": "00000000",
"decimal": 28
},
{
"key": "y",
"modifier": "00000000",
"decimal": 9
},
{
"key": "u",
"modifier": "00000000",
"decimal": 10
},
{
"key": "i",
"modifier": "00000000",
"decimal": 6
},
{
"key": "o",
"modifier": "00000000",
"decimal": 21
},
{
"key": "p",
"modifier": "00000000",
"decimal": 15
},
{
"key": "[",
"modifier": "00000000",
"decimal": 56
},
{
"key": "]",
"modifier": "00000000",
"decimal": 46
},
{
"key": "\\",
"modifier": "00000000",
"decimal": 49
},
{
"key": "a",
"modifier": "00000000",
"decimal": 4
},
{
"key": "s",
"modifier": "00000000",
"decimal": 18
},
{
"key": "d",
"modifier": "00000000",
"decimal": 8
},
{
"key": "f",
"modifier": "00000000",
"decimal": 24
},
{
"key": "g",
"modifier": "00000000",
"decimal": 12
},
{
"key": "h",
"modifier": "00000000",
"decimal": 7
},
{
"key": "j",
"modifier": "00000000",
"decimal": 11
},
{
"key": "k",
"modifier": "00000000",
"decimal": 23
},
{
"key": "l",
"modifier": "00000000",
"decimal": 17
},
{
"key": ";",
"modifier": "00000000",
"decimal": 22
},
{
"key": "'",
"modifier": "00000000",
"decimal": 45
},
{
"key": "z",
"modifier": "00000000",
"decimal": 51
},
{
"key": "x",
"modifier": "00000000",
"decimal": 20
},
{
"key": "c",
"modifier": "00000000",
"decimal": 13
},
{
"key": "v",
"modifier": "00000000",
"decimal": 14
},
{
"key": "b",
"modifier": "00000000",
"decimal": 27
},
{
"key": "n",
"modifier": "00000000",
"decimal": 5
},
{
"key": "m",
"modifier": "00000000",
"decimal": 16
},
{
"key": ",",
"modifier": "00000000",
"decimal": 26
},
{
"key": ".",
"modifier": "00000000",
"decimal": 25
},
{
"key": "/",
"modifier": "00000000",
"decimal": 29
},
{
"key": "~",
"modifier": "00000010",
"decimal": 53
},
{
"key": "!",
"modifier": "00000010",
"decimal": 30
},
{
"key": "@",
"modifier": "00000010",
"decimal": 31
},
{
"key": "#",
"modifier": "00000010",
"decimal": 32
},
{
"key": "$",
"modifier": "00000010",
"decimal": 33
},
{
"key": "%",
"modifier": "00000010",
"decimal": 34
},
{
"key": "^",
"modifier": "00000010",
"decimal": 35
},
{
"key": "&",
"modifier": "00000010",
"decimal": 36
},
{
"key": "*",
"modifier": "00000010",
"decimal": 37
},
{
"key": "(",
"modifier": "00000010",
"decimal": 38
},
{
"key": ")",
"modifier": "00000010",
"decimal": 39
},
{
"key": "_",
"modifier": "00000010",
"decimal": 47
},
{
"key": "+",
"modifier": "00000010",
"decimal": 48
},
{
"key": "Q",
"modifier": "00000010",
"decimal": 52
},
{
"key": "W",
"modifier": "00000010",
"decimal": 54
},
{
"key": "E",
"modifier": "00000010",
"decimal": 55
},
{
"key": "R",
"modifier": "00000010",
"decimal": 19
},
{
"key": "T",
"modifier": "00000010",
"decimal": 28
},
{
"key": "Y",
"modifier": "00000010",
"decimal": 9
},
{
"key": "U",
"modifier": "00000010",
"decimal": 10
},
{
"key": "I",
"modifier": "00000010",
"decimal": 6
},
{
"key": "O",
"modifier": "00000010",
"decimal": 21
},
{
"key": "P",
"modifier": "00000010",
"decimal": 15
},
{
"key": "{",
"modifier": "00000010",
"decimal": 56
},
{
"key": "}",
"modifier": "00000010",
"decimal": 46
},
{
"key": "|",
"modifier": "00000010",
"decimal": 49
},
{
"key": "A",
"modifier": "00000010",
"decimal": 4
},
{
"key": "S",
"modifier": "00000010",
"decimal": 18
},
{
"key": "D",
"modifier": "00000010",
"decimal": 8
},
{
"key": "F",
"modifier": "00000010",
"decimal": 24
},
{
"key": "G",
"modifier": "00000010",
"decimal": 12
},
{
"key": "H",
"modifier": "00000010",
"decimal": 7
},
{
"key": "J",
"modifier": "00000010",
"decimal": 11
},
{
"key": "K",
"modifier": "00000010",
"decimal": 23
},
{
"key": "L",
"modifier": "00000010",
"decimal": 17
},
{
"key": ":",
"modifier": "00000010",
"decimal": 22
},
{
"key": "\"",
"modifier": "00000010",
"decimal": 45
},
{
"key": "Z",
"modifier": "00000010",
"decimal": 51
},
{
"key": "X",
"modifier": "00000010",
"decimal": 20
},
{
"key": "C",
"modifier": "00000010",
"decimal": 13
},
{
"key": "V",
"modifier": "00000010",
"decimal": 14
},
{
"key": "B",
"modifier": "00000010",
"decimal": 27
},
{
"key": "N",
"modifier": "00000010",
"decimal": 5
},
{
"key": "M",
"modifier": "00000010",
"decimal": 16
},
{
"key": "<",
"modifier": "00000010",
"decimal": 26
},
{
"key": ">",
"modifier": "00000010",
"decimal": 25
},
{
"key": "?",
"modifier": "00000010",
"decimal": 29
}
]

96
main.go
View File

@ -1,12 +1,26 @@
package main
import (
"bufio"
"encoding/binary"
"fmt"
"encoding/json"
"io"
"io/ioutil"
"os"
"path"
"strings"
"github.com/alexflint/go-arg"
)
type Key struct {
name rune
modifier string
decimal int
}
type Keys []Key
const (
LCTRL byte = 1 << iota
LSHIFT
@ -20,28 +34,76 @@ const (
func Press(press [8]byte, file io.Writer) {
binary.Write(file, binary.BigEndian, press[:])
binary.Write(file, binary.BigEndian, [8]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})
}
func Hold(press [8]byte, file io.Writer) {
binary.Write(file, binary.BigEndian, press[:])
}
func main() {
var (
press [8]byte = [8]byte{0x00, 0x00, 0x51, 0x00, 0x00, 0x00, 0x00, 0x00} // down
press1 [8]byte = [8]byte{0x00, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x00} // backspace
press2 [8]byte = [8]byte{0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00} // t
unpress [8]byte = [8]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
args struct {
SHORTCUT string `arg:"-S,help:Keymap cycle shortcut"`
ORDER []string `arg:positional,help:Order of keymaps`
}
hidg0 *os.File
err error
keymapsF []os.FileInfo
keys map[string]Keys
cfgPath = path.Join(os.Getenv("XDG_CONFIG_HOME"), "hid")
stdin = bufio.NewReader(os.Stdin)
currentKeyMap int
good bool
)
file, err := os.OpenFile("/dev/hidg0", os.O_WRONLY, os.ModePerm)
fmt.Println(err)
for j := 1; j <= 1000; j++ {
Press(press, file)
Press(unpress, file)
Press(press1, file)
Press(unpress, file)
Press(press2, file)
Press(unpress, file)
arg.MustParse(&args)
keymapsF, err = ioutil.ReadDir(cfgPath)
if err != nil {
panic(err)
}
file.Close()
hidg0, err = os.OpenFile("/dev/hidg0", os.O_WRONLY, os.ModePerm)
if err != nil {
panic(err)
}
for _, file := range keymapsF {
var (
ext string
)
ext = path.Ext(file.Name())
if strings.ToLower(ext) == "json" {
var (
tmp Keys
T *os.File
content []byte
)
T, err = os.Open(strings.TrimSuffix(file.Name(), ext))
if err != nil {
panic(err)
}
content, err = ioutil.ReadAll(T)
if err != nil {
panic(err)
}
json.Unmarshal(content, tmp)
keys[strings.TrimSuffix(file.Name(), ext)] = tmp
T.Close()
}
}
for good {
var r rune
r, _, err = stdin.ReadRune()
for keys[args.ORDER[currentKeyMap]][r].name != r {
Press([8]byte{LCTRL, 0x00, 0x57, 0x00, 0x00, 0x00, 0x00, 0x00}, hidg0)
currentKeyMap++
}
}
hidg0.Close()
}

87
q.json
View File

@ -1,87 +0,0 @@
{
"!":"shift 1"
""":"shift '"
"#":"#"
"$":"$"
"%":"%"
"&":"&"
"'":"'"
"(":"("
")":")"
"*":"*"
"+":"+"
",":","
"-":"-"
".":"."
"/":"/"
":":":"
";":";"
"<":"<"
"=":"="
">":">"
"?":"?"
"@":"@"
"A":"A"
"B":"B"
"C":"C"
"D":"D"
"E":"E"
"F":"F"
"G":"G"
"H":"H"
"I":"I"
"J":"J"
"K":"K"
"L":"L"
"M":"M"
"N":"N"
"O":"O"
"P":"P"
"Q":"Q"
"R":"R"
"S":"S"
"T":"T"
"U":"U"
"V":"V"
"W":"W"
"X":"X"
"Y":"Y"
"Z":"Z"
"[":"["
"\":"\"
"]":"]"
"^":"^"
"_":"_"
"a":"a"
"b":"b"
"c":"c"
"d":"d"
"e":"e"
"f":"f"
"g":"g"
"h":"h"
"i":"i"
"j":"j"
"k":"k"
"l":"l"
"m":"m"
"n":"n"
"o":"o"
"p":"p"
"q":"q"
"r":"r"
"s":"s"
"t":"t"
"u":"u"
"v":"v"
"w":"w"
"x":"x"
"y":"y"
"z":"z"
"{":"{"
"|":"|"
"}":"}"
"~":"~"
"\n":"n"
"\t":"t"

472
qwerty.json Normal file
View File

@ -0,0 +1,472 @@
[
{
"name": "0",
"modifier": "00000000",
"decimal": 39
},
{
"name": "1",
"modifier": "00000000",
"decimal": 30
},
{
"name": "2",
"modifier": "00000000",
"decimal": 31
},
{
"name": "3",
"modifier": "00000000",
"decimal": 32
},
{
"name": "4",
"modifier": "00000000",
"decimal": 33
},
{
"name": "5",
"modifier": "00000000",
"decimal": 34
},
{
"name": "6",
"modifier": "00000000",
"decimal": 35
},
{
"name": "7",
"modifier": "00000000",
"decimal": 36
},
{
"name": "8",
"modifier": "00000000",
"decimal": 37
},
{
"name": "9",
"modifier": "00000000",
"decimal": 38
},
{
"name": "`",
"modifier": "00000000",
"decimal": 53
},
{
"name": "[",
"modifier": "00000000",
"decimal": 47
},
{
"name": "]",
"modifier": "00000000",
"decimal": 48
},
{
"name": "'",
"modifier": "00000000",
"decimal": 52
},
{
"name": ",",
"modifier": "00000000",
"decimal": 54
},
{
"name": ".",
"modifier": "00000000",
"decimal": 55
},
{
"name": "p",
"modifier": "00000000",
"decimal": 19
},
{
"name": "y",
"modifier": "00000000",
"decimal": 28
},
{
"name": "f",
"modifier": "00000000",
"decimal": 9
},
{
"name": "g",
"modifier": "00000000",
"decimal": 10
},
{
"name": "c",
"modifier": "00000000",
"decimal": 6
},
{
"name": "r",
"modifier": "00000000",
"decimal": 21
},
{
"name": "l",
"modifier": "00000000",
"decimal": 15
},
{
"name": "/",
"modifier": "00000000",
"decimal": 56
},
{
"name": "=",
"modifier": "00000000",
"decimal": 46
},
{
"name": "\\",
"modifier": "00000000",
"decimal": 49
},
{
"name": "a",
"modifier": "00000000",
"decimal": 4
},
{
"name": "o",
"modifier": "00000000",
"decimal": 18
},
{
"name": "e",
"modifier": "00000000",
"decimal": 8
},
{
"name": "u",
"modifier": "00000000",
"decimal": 24
},
{
"name": "i",
"modifier": "00000000",
"decimal": 12
},
{
"name": "d",
"modifier": "00000000",
"decimal": 7
},
{
"name": "h",
"modifier": "00000000",
"decimal": 11
},
{
"name": "t",
"modifier": "00000000",
"decimal": 23
},
{
"name": "n",
"modifier": "00000000",
"decimal": 17
},
{
"name": "s",
"modifier": "00000000",
"decimal": 22
},
{
"name": "-",
"modifier": "00000000",
"decimal": 45
},
{
"name": ";",
"modifier": "00000000",
"decimal": 51
},
{
"name": "q",
"modifier": "00000000",
"decimal": 20
},
{
"name": "j",
"modifier": "00000000",
"decimal": 13
},
{
"name": "k",
"modifier": "00000000",
"decimal": 14
},
{
"name": "x",
"modifier": "00000000",
"decimal": 27
},
{
"name": "b",
"modifier": "00000000",
"decimal": 5
},
{
"name": "m",
"modifier": "00000000",
"decimal": 16
},
{
"name": "w",
"modifier": "00000000",
"decimal": 26
},
{
"name": "v",
"modifier": "00000000",
"decimal": 25
},
{
"name": "z",
"modifier": "00000000",
"decimal": 29
},
{
"name": "~",
"modifier": "00000010",
"decimal": 53
},
{
"name": "!",
"modifier": "00000010",
"decimal": 30
},
{
"name": "@",
"modifier": "00000010",
"decimal": 31
},
{
"name": "#",
"modifier": "00000010",
"decimal": 32
},
{
"name": "$",
"modifier": "00000010",
"decimal": 33
},
{
"name": "%",
"modifier": "00000010",
"decimal": 34
},
{
"name": "^",
"modifier": "00000010",
"decimal": 35
},
{
"name": "&",
"modifier": "00000010",
"decimal": 36
},
{
"name": "*",
"modifier": "00000010",
"decimal": 37
},
{
"name": "(",
"modifier": "00000010",
"decimal": 38
},
{
"name": ")",
"modifier": "00000010",
"decimal": 39
},
{
"name": "{",
"modifier": "00000010",
"decimal": 47
},
{
"name": "}",
"modifier": "00000010",
"decimal": 48
},
{
"name": "\"",
"modifier": "00000010",
"decimal": 52
},
{
"name": "<",
"modifier": "00000010",
"decimal": 54
},
{
"name": ">",
"modifier": "00000010",
"decimal": 55
},
{
"name": "P",
"modifier": "00000010",
"decimal": 19
},
{
"name": "Y",
"modifier": "00000010",
"decimal": 28
},
{
"name": "F",
"modifier": "00000010",
"decimal": 9
},
{
"name": "G",
"modifier": "00000010",
"decimal": 10
},
{
"name": "C",
"modifier": "00000010",
"decimal": 6
},
{
"name": "R",
"modifier": "00000010",
"decimal": 21
},
{
"name": "L",
"modifier": "00000010",
"decimal": 15
},
{
"name": "?",
"modifier": "00000010",
"decimal": 56
},
{
"name": "+",
"modifier": "00000010",
"decimal": 46
},
{
"name": "|",
"modifier": "00000010",
"decimal": 49
},
{
"name": "A",
"modifier": "00000010",
"decimal": 4
},
{
"name": "O",
"modifier": "00000010",
"decimal": 18
},
{
"name": "E",
"modifier": "00000010",
"decimal": 8
},
{
"name": "U",
"modifier": "00000010",
"decimal": 24
},
{
"name": "I",
"modifier": "00000010",
"decimal": 12
},
{
"name": "D",
"modifier": "00000010",
"decimal": 7
},
{
"name": "H",
"modifier": "00000010",
"decimal": 11
},
{
"name": "T",
"modifier": "00000010",
"decimal": 23
},
{
"name": "N",
"modifier": "00000010",
"decimal": 17
},
{
"name": "S",
"modifier": "00000010",
"decimal": 22
},
{
"name": "_",
"modifier": "00000010",
"decimal": 45
},
{
"name": ":",
"modifier": "00000010",
"decimal": 51
},
{
"name": "Q",
"modifier": "00000010",
"decimal": 20
},
{
"name": "J",
"modifier": "00000010",
"decimal": 13
},
{
"name": "K",
"modifier": "00000010",
"decimal": 14
},
{
"name": "X",
"modifier": "00000010",
"decimal": 27
},
{
"name": "B",
"modifier": "00000010",
"decimal": 5
},
{
"name": "M",
"modifier": "00000010",
"decimal": 16
},
{
"name": "W",
"modifier": "00000010",
"decimal": 26
},
{
"name": "V",
"modifier": "00000010",
"decimal": 25
},
{
"name": "Z",
"modifier": "00000010",
"decimal": 29
}
]