Initial app done
This commit is contained in:
parent
498eb465a8
commit
72c447dfb8
40
main.go
40
main.go
@ -4,6 +4,7 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
@ -21,6 +22,11 @@ type Key struct {
|
|||||||
|
|
||||||
type Keys []Key
|
type Keys []Key
|
||||||
|
|
||||||
|
type Args struct {
|
||||||
|
SHORTCUT string `arg:"-S,help:Keymap cycle shortcut"`
|
||||||
|
ORDER []string `arg:positional,help:Order of keymaps`
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
LCTRL byte = 1 << iota
|
LCTRL byte = 1 << iota
|
||||||
LSHIFT
|
LSHIFT
|
||||||
@ -41,12 +47,19 @@ func Hold(press [8]byte, file io.Writer) {
|
|||||||
binary.Write(file, binary.BigEndian, press[:])
|
binary.Write(file, binary.BigEndian, press[:])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func changeKeymap(r rune, keys map[string]Keys, args Args, hidg0 *os.File, currentKeyMap *int) {
|
||||||
|
for keys[args.ORDER[(*currentKeyMap)]][r].name != r {
|
||||||
|
Press([8]byte{LCTRL, 0x00, 0x57, 0x00, 0x00, 0x00, 0x00, 0x00}, hidg0)
|
||||||
|
*currentKeyMap++
|
||||||
|
if *currentKeyMap == len(keys) {
|
||||||
|
panic("key not in keymap")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var (
|
var (
|
||||||
args struct {
|
args Args
|
||||||
SHORTCUT string `arg:"-S,help:Keymap cycle shortcut"`
|
|
||||||
ORDER []string `arg:positional,help:Order of keymaps`
|
|
||||||
}
|
|
||||||
hidg0 *os.File
|
hidg0 *os.File
|
||||||
err error
|
err error
|
||||||
keymapsF []os.FileInfo
|
keymapsF []os.FileInfo
|
||||||
@ -54,7 +67,6 @@ func main() {
|
|||||||
cfgPath = path.Join(os.Getenv("XDG_CONFIG_HOME"), "hid")
|
cfgPath = path.Join(os.Getenv("XDG_CONFIG_HOME"), "hid")
|
||||||
stdin = bufio.NewReader(os.Stdin)
|
stdin = bufio.NewReader(os.Stdin)
|
||||||
currentKeyMap int
|
currentKeyMap int
|
||||||
good bool
|
|
||||||
)
|
)
|
||||||
arg.MustParse(&args)
|
arg.MustParse(&args)
|
||||||
keymapsF, err = ioutil.ReadDir(cfgPath)
|
keymapsF, err = ioutil.ReadDir(cfgPath)
|
||||||
@ -94,13 +106,21 @@ func main() {
|
|||||||
T.Close()
|
T.Close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for good {
|
for {
|
||||||
var r rune
|
var (
|
||||||
|
r rune
|
||||||
|
flag byte
|
||||||
|
report [6]byte
|
||||||
|
)
|
||||||
|
|
||||||
r, _, err = stdin.ReadRune()
|
r, _, err = stdin.ReadRune()
|
||||||
for keys[args.ORDER[currentKeyMap]][r].name != r {
|
if err != nil {
|
||||||
Press([8]byte{LCTRL, 0x00, 0x57, 0x00, 0x00, 0x00, 0x00, 0x00}, hidg0)
|
panic(err)
|
||||||
currentKeyMap++
|
|
||||||
}
|
}
|
||||||
|
changeKeymap(r, keys, args, hidg0, ¤tKeyMap)
|
||||||
|
_, err = fmt.Sscanf(keys[args.ORDER[currentKeyMap]][r].modifier, "%b", flag)
|
||||||
|
binary.PutVarint(report[:], int64(keys[args.ORDER[currentKeyMap]][r].decimal))
|
||||||
|
Press([8]byte{flag, 0, report[0], report[1], report[2], report[3], report[4], report[5]}, hidg0)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user