Compare commits

...

13 Commits

Author SHA1 Message Date
Timmy Welch
d70c691ac7 Fix shortcut parsing and keymap list 2024-04-17 17:30:19 -07:00
Timmy Welch
572af746fa Change module location 2024-04-17 17:14:23 -07:00
Timmy Welch
f6967e5f83 Improve keymap changing 2024-04-17 17:14:09 -07:00
lordwelch
5a4c207159 Fix flags 2022-05-13 09:49:13 -07:00
lordwelch
0206ba448e Enable go module
Set go version to 1.18
Add arguments to set press delay and release delay
Add better handling for unknown characters
2022-05-13 09:44:04 -07:00
lordwelch
0bbf455bc7 Remove logging 2021-02-26 13:11:19 -08:00
lordwelch
a594b3044c Add support for modifier keys (eg CTRL+D, CTRL+SHIFT+D) 2021-02-26 12:32:23 -08:00
lordwelch
7244a85ecd Fix dvorak keymap 2020-03-18 15:13:42 -07:00
lordwelch
d1b2d5623a Add a clean exit for not providing a keymap to use 2020-03-05 23:56:51 -08:00
lordwelch
c2f2d16097 Fix Nil map error 2020-03-05 14:46:17 -08:00
lordwelch
7441c3e637 Use a struct as a base instead of bare functions in a library
Added error reporting for Keyboard type
Added a file flag to read the input from
Fixed odd keymap path handling
2020-03-05 12:52:27 -08:00
lordwelch
03ec054d8b Fix an off by one error 2020-01-31 19:44:33 -08:00
lordwelch
a0e2601d2f keymaps
Fix Dvorak ordering
Remake tengwar-f
2019-08-04 16:27:54 -07:00
9 changed files with 1399 additions and 594 deletions

View File

@ -30,8 +30,18 @@ type Key struct {
// A Keymap is a json representation of the unicode rune mapped to its USB HID value
type Keymap map[string]Key
// Keyboard is a type to attach the methods to if someone wants to use it
type Keyboard struct{}
type Keyboard struct {
PressDelay time.Duration // PressDelay is the time in ms to delay before sending a press event
ReleaseDelay time.Duration // ReleaseDelay is the time in ms to wait before sending the release event
KeymapOrder []string // Keymap Order is the order in which the specified keymaps cycle on the computer
KeymapShortcut [8]byte // KeymapShortcut is the key combo that will cycle the current keymap by one
ErrOnUnknownKey bool // ErrOnUnknownKey whether or not to fail if the unicode rune is invalid or is not in the specified keymaps
KeymapPath string // KeymapPath is the pathe to where the keymap files are stored
currentKeyMap int
keymaps map[string]Keymap
flags map[string]byte
Hidg0 io.Writer
}
// bit flag of modifier keys
const (
@ -47,16 +57,7 @@ const (
)
var (
PressDelay time.Duration // PressDelay is the time in ms to delay before sending a press event
ReleaseDelay time.Duration // ReleaseDelay is the time in ms to wait before sending the release event
KeymapOrder []string // Keymap Order is the order in which the specified keymaps cycle on the computer
KeymapShortcut [8]byte // KeymapShortcut is the key combo that will cycle the current keymap by one
ErrOnUnknownKey bool // ErrOnUnknownKey whether or not to fail if the unicode rune is invalid or is not in the specified keymaps
KeymapPath string // KeymapPath is the pathe to where the keymap files are stored
currentKeyMap int
keys = make(map[string]Keymap)
flags = map[string]byte{
Modifiers = map[string]byte{
"LSHIFT": LSHIFT,
"LCTRL": LCTRL,
"LALT": LALT,
@ -67,21 +68,34 @@ var (
"RSUPER": RSUPER,
"NONE": NONE,
}
Hidg0 io.Writer
AllModifiers = []string{
"LSHIFT",
"LCTRL",
"LALT",
"LSUPER",
"RSHIFT",
"RCTRL",
"RALT",
"RSUPER",
"NONE",
}
)
func (k Keyboard) Write(p []byte) (n int, err error) {
return write(p)
}
func Write(r io.Reader) error {
_, err := io.Copy(Keyboard{}, r)
return err
func NewKeyboard(Modifiers map[string]byte, kemapOrder []string, KeymapPath string, hidg0 io.Writer) *Keyboard {
return &Keyboard{
flags: Modifiers,
KeymapOrder: kemapOrder,
KeymapPath: KeymapPath,
Hidg0: hidg0,
}
}
// io.writer probably isn't the best interface to use for this
func write(p []byte) (n int, err error) {
var index int
func (k *Keyboard) Write(p []byte) (int, error) {
var (
index int
err error
)
for index < len(p) {
var (
r rune
@ -98,13 +112,21 @@ func write(p []byte) (n int, err error) {
if r == utf8.RuneError {
return index, fmt.Errorf("invalid rune: 0x%X", p[index]) // This probably screws things up if the last rune in 'p' is incomplete
}
cur, ok := CurrentKeymap()[string(r)]
cur, ok := k.CurrentKeymap()[string(r)]
if !ok {
if i == 2 { // can't press two keys from different keymaps
if !changeKeymap(r) && ErrOnUnknownKey {
return index, fmt.Errorf("rune not in keymap: %c", r)
if i == 2 { // We can change the keymap if we are on the first key
ok, err = k.changeKeymap(r)
if !ok { // rune does not have a mapping
if k.ErrOnUnknownKey {
if err != nil {
return index, err
}
return index, fmt.Errorf("rune not in keymap: %c", r)
}
index += s
break press
}
} else {
} else { // rune does not have a mapping in this keymaps
break press
}
}
@ -112,29 +134,33 @@ func write(p []byte) (n int, err error) {
switch {
case cur.PressDelayDelimiter:
var n int
n, PressDelay = parseDelay(p[index+s:])
n, k.PressDelay = parseDelay(p[index+s:])
index += s + n
break press
case cur.ReleaseDelayDelimiter:
var n int
n, ReleaseDelay = parseDelay(p[index+s:])
n, k.ReleaseDelay = parseDelay(p[index+s:])
index += s + n
break press
case cur.Comment:
var n int
n = bytes.Index(p[index+s:], []byte("\n"))
n = bytes.Index(p[index+s:], []byte("\n")) + 1
if n < 0 {
n = 0
}
index += s + n
break press
case r == '␀':
// Causes immediate key press useful for modifier keys
index += s
break press
default:
// Calculate next modifier byte
for _, v := range cur.Modifier {
mod = mod | flags[v]
mod |= k.flags[v]
}
// Set the modifier if it is the first key otherwise
@ -142,29 +168,41 @@ func write(p []byte) (n int, err error) {
if i == 2 {
flag = mod
} else if flag != mod {
break press
// This is the second key press if the previous one was a modifier only Decimal == 0 then take the current key as well
if report[i-1] != 0 {
break press
}
// Add the modifier of the current key eg 'D' adds shift; 'd' does not
flag |= mod
}
// Check for duplicate key press. You can't press a key if it is already pressed.
// Check for duplicate key press. You can't press a key if it is already pressed, unless it is 0 indicating a modifier.
for u := 2; u < i; u++ {
if cur.Decimal == report[u] {
if cur.Decimal == report[u] && cur.Decimal != 0 {
break press
}
}
}
report[i] = cur.Decimal
index += s
if PressDelay > 0 {
break press
if k.PressDelay > 0 {
// This is the first key press if this is a modifier only Decimal == 0 then take the next key as well
if report[i] != 0 {
break press
}
}
}
report[0] = flag
r, _ = utf8.DecodeRune(p[index-1:])
Press(report, Hidg0)
delay(PressDelay)
err = k.Press(report, k.Hidg0)
if err != nil {
return index, err
}
k.delay(k.PressDelay)
}
err = k.keymapto0() // To make it reproducible
if err != nil {
return index, err
}
keymapto0() // To make it reproducible
return index, nil
}
@ -194,69 +232,87 @@ func parseDelay(buffer []byte) (count int, delay time.Duration) {
return 0, 0
}
func delay(Delay time.Duration) {
func (k *Keyboard) delay(Delay time.Duration) {
if Delay > 0 {
if syncCheck, ok := Hidg0.(syncer); ok {
syncCheck.Sync()
if syncCheck, ok := k.Hidg0.(syncer); ok {
_ = syncCheck.Sync()
}
time.Sleep(Delay)
}
}
func Press(press [8]byte, file io.Writer) {
file.Write(press[:])
delay(ReleaseDelay)
file.Write([]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})
}
func Hold(press [8]byte, file io.Writer) {
file.Write(press[:])
}
func keymapto0() {
if len(KeymapOrder) > 1 {
for i := 0; i < len(KeymapOrder)-(currentKeyMap); i++ {
Press([8]byte{LALT, 0x00, 0x39, 0x00, 0x00, 0x00, 0x00, 0x00}, Hidg0)
}
currentKeyMap = 0
func (k *Keyboard) Press(press [8]byte, file io.Writer) error {
_, err1 := file.Write(press[:])
k.delay(k.ReleaseDelay)
_, err2 := file.Write([]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})
if err1 != nil {
return err1
}
if err2 != nil {
return err2
}
return nil
}
func changeKeymap(r rune) bool {
buf := bytes.NewBuffer(make([]byte, 0, 8*len(KeymapOrder))) // To batch shortcut presses
func (k *Keyboard) Hold(press [8]byte, file io.Writer) error {
_, err := file.Write(press[:])
return err
}
for i := 0; i < len(KeymapOrder); i++ {
_, ok := CurrentKeymap()[string(r)]
func (k *Keyboard) keymapto0() error {
if len(k.KeymapOrder) > 1 {
for i := 0; i < len(k.KeymapOrder)-(k.currentKeyMap); i++ {
err := k.Press(k.KeymapShortcut, k.Hidg0)
if err != nil {
return err
}
}
k.currentKeyMap = 0
}
return nil
}
func (k *Keyboard) changeKeymap(r rune) (bool, error) {
var err error
buf := bytes.NewBuffer(make([]byte, 0, 8*len(k.KeymapOrder))) // To batch shortcut presses
for i := 0; i < len(k.KeymapOrder); i++ {
_, ok := k.CurrentKeymap()[string(r)]
if ok {
Hidg0.Write(buf.Bytes())
return true
_, err = k.Hidg0.Write(buf.Bytes())
return true, err
}
Press(KeymapShortcut, buf)
if currentKeyMap == len(KeymapOrder)-1 {
currentKeyMap = 0
err = k.Press(k.KeymapShortcut, buf)
if err != nil {
return false, err
}
if k.currentKeyMap == len(k.KeymapOrder)-1 {
k.currentKeyMap = 0
} else {
currentKeyMap++
k.currentKeyMap++
}
}
return false
return false, nil
}
func CurrentKeymap() Keymap {
keymap, ok := keys[KeymapOrder[currentKeyMap]]
func (k *Keyboard) CurrentKeymap() Keymap {
keymap, ok := k.keymaps[k.KeymapOrder[k.currentKeyMap]]
if ok {
return keymap
}
return LoadKeymap(KeymapOrder[currentKeyMap])
if k.keymaps == nil {
k.keymaps = make(map[string]Keymap)
}
k.keymaps[k.KeymapOrder[k.currentKeyMap]] = LoadKeymap(k.KeymapOrder[k.currentKeyMap], k.KeymapPath)
return k.keymaps[k.KeymapOrder[k.currentKeyMap]]
}
func LoadKeymap(keymapName string) Keymap {
func LoadKeymap(keymapName string, KeymapPath string) Keymap {
var (
err error
content []byte
file = path.Join(path.Join(KeymapPath, "hid"), keymapName+".json")
tmp = make(Keymap, 0)
file = path.Join(KeymapPath, keymapName+".json")
tmp = make(Keymap)
)
fmt.Println(file)
content, err = ioutil.ReadFile(file)
@ -268,7 +324,5 @@ func LoadKeymap(keymapName string) Keymap {
if err != nil {
return nil
}
keys[keymapName] = tmp
return keys[keymapName]
return tmp
}

121
ghid/keys.go Normal file
View File

@ -0,0 +1,121 @@
package hid
var (
StandardKeys = map[string]byte{
"␀": 0x00,
"": 0x00,
"a": 0x04,
"A": 0x04,
"b": 0x05,
"B": 0x05,
"c": 0x06,
"C": 0x06,
"d": 0x07,
"D": 0x07,
"e": 0x08,
"E": 0x08,
"f": 0x09,
"F": 0x09,
"g": 0x0A,
"G": 0x0A,
"h": 0x0B,
"H": 0x0B,
"i": 0x0C,
"I": 0x0C,
"j": 0x0D,
"J": 0x0D,
"k": 0x0E,
"K": 0x0E,
"l": 0x0F,
"L": 0x0F,
"m": 0x10,
"M": 0x10,
"n": 0x11,
"N": 0x11,
"o": 0x12,
"O": 0x12,
"p": 0x13,
"P": 0x13,
"q": 0x14,
"Q": 0x14,
"r": 0x15,
"R": 0x15,
"s": 0x16,
"S": 0x16,
"t": 0x17,
"T": 0x17,
"u": 0x18,
"U": 0x18,
"v": 0x19,
"V": 0x19,
"w": 0x1A,
"W": 0x1A,
"x": 0x1B,
"X": 0x1B,
"y": 0x1C,
"Y": 0x1C,
"z": 0x1D,
"Z": 0x1D,
"!": 0x1E,
"1": 0x1E,
"2": 0x1F,
"@": 0x1F,
"#": 0x20,
"3": 0x20,
"$": 0x21,
"4": 0x21,
"%": 0x22,
"5": 0x22,
"6": 0x23,
"^": 0x23,
"&": 0x24,
"7": 0x24,
"*": 0x25,
"8": 0x25,
"(": 0x26,
"9": 0x26,
")": 0x27,
"0": 0x27,
"\n": 0x28,
"⎋": 0x29, // esc
"␛": 0x29, // esc
"⌫": 0x2A, // backspace
"\t": 0x2B,
" ": 0x2C,
"-": 0x2D,
"_": 0x2D,
"+": 0x2E,
"=": 0x2E,
"[": 0x2F,
"{": 0x2F,
"]": 0x30,
"}": 0x30,
"\\": 0x31,
"|": 0x31,
":": 0x33,
";": 0x33,
"'": 0x34,
"\"": 0x34,
"`": 0x35,
"~": 0x35,
",": 0x36,
"<": 0x36,
".": 0x37,
">": 0x37,
"/": 0x38,
"?": 0x38,
"⇪": 0x39,
"⎙": 0x46,
"⏸️": 0x48,
"⎀": 0x49,
"↖": 0x4A,
"⇞": 0x4B,
"⌦": 0x4C,
"↘": 0x4D,
"⇟": 0x4E,
"→": 0x4F,
"←": 0x50,
"↑": 0x51,
"↓": 0x52,
}
)

3
go.mod Normal file
View File

@ -0,0 +1,3 @@
module gitea.narnian.us/lordwelch/hid
go 1.18

View File

@ -1,8 +1,4 @@
{
"0": {
"modifier": ["NONE"],
"decimal": 39
},
"1": {
"modifier": ["NONE"],
"decimal": 30
@ -39,10 +35,26 @@
"modifier": ["NONE"],
"decimal": 38
},
"0": {
"modifier": ["NONE"],
"decimal": 39
},
"[": {
"modifier": ["NONE"],
"decimal": 45
},
"]": {
"modifier": ["NONE"],
"decimal": 46
},
"!": {
"modifier": ["LSHIFT"],
"decimal": 30
},
"@": {
"modifier": ["LSHIFT"],
"decimal": 31
},
"#": {
"modifier": ["LSHIFT"],
"decimal": 32
@ -55,13 +67,17 @@
"modifier": ["LSHIFT"],
"decimal": 34
},
"^": {
"modifier": ["LSHIFT"],
"decimal": 35
},
"&": {
"modifier": ["LSHIFT"],
"decimal": 36
},
"'": {
"modifier": ["NONE"],
"decimal": 20
"*": {
"modifier": ["LSHIFT"],
"decimal": 37
},
"(": {
"modifier": ["LSHIFT"],
@ -71,210 +87,34 @@
"modifier": ["LSHIFT"],
"decimal": 39
},
"*": {
"{": {
"modifier": ["LSHIFT"],
"decimal": 37
"decimal": 45
},
"+": {
"}": {
"modifier": ["LSHIFT"],
"decimal": 48
"decimal": 46
},
"'": {
"modifier": ["NONE"],
"decimal": 20
},
",": {
"modifier": ["NONE"],
"decimal": 26
},
"-": {
"modifier": ["NONE"],
"decimal": 52
},
".": {
"modifier": ["NONE"],
"decimal": 8
},
"/": {
"p": {
"modifier": ["NONE"],
"decimal": 47
},
":": {
"modifier": ["LSHIFT"],
"decimal": 29
},
";": {
"modifier": ["NONE"],
"decimal": 29
},
"<": {
"modifier": ["LSHIFT"],
"decimal": 26
},
"=": {
"modifier": ["NONE"],
"decimal": 48
},
">": {
"modifier": ["LSHIFT"],
"decimal": 8
},
"?": {
"modifier": ["LSHIFT"],
"decimal": 47
},
"@": {
"modifier": ["LSHIFT"],
"decimal": 31
},
"A": {
"modifier": ["LSHIFT"],
"decimal": 4
},
"B": {
"modifier": ["LSHIFT"],
"decimal": 17
},
"C": {
"modifier": ["LSHIFT"],
"decimal": 12
},
"D": {
"modifier": ["LSHIFT"],
"decimal": 11
},
"E": {
"modifier": ["LSHIFT"],
"decimal": 7
},
"F": {
"modifier": ["LSHIFT"],
"decimal": 28
},
"G": {
"modifier": ["LSHIFT"],
"decimal": 24
},
"H": {
"modifier": ["LSHIFT"],
"decimal": 13
},
"I": {
"modifier": ["LSHIFT"],
"decimal": 10
},
"J": {
"modifier": ["LSHIFT"],
"decimal": 6
},
"K": {
"modifier": ["LSHIFT"],
"decimal": 25
},
"L": {
"modifier": ["LSHIFT"],
"decimal": 19
},
"M": {
"modifier": ["LSHIFT"],
"decimal": 16
},
"N": {
"modifier": ["LSHIFT"],
"decimal": 15
},
"O": {
"modifier": ["LSHIFT"],
"decimal": 22
},
"P": {
"modifier": ["LSHIFT"],
"decimal": 21
},
"Q": {
"modifier": ["LSHIFT"],
"decimal": 27
},
"R": {
"modifier": ["LSHIFT"],
"decimal": 18
},
"S": {
"modifier": ["LSHIFT"],
"decimal": 51
},
"T": {
"modifier": ["LSHIFT"],
"decimal": 14
},
"U": {
"modifier": ["LSHIFT"],
"decimal": 9
},
"V": {
"modifier": ["LSHIFT"],
"decimal": 55
},
"W": {
"modifier": ["LSHIFT"],
"decimal": 54
},
"X": {
"modifier": ["LSHIFT"],
"decimal": 5
},
"Y": {
"modifier": ["LSHIFT"],
"y": {
"modifier": ["NONE"],
"decimal": 23
},
"Z": {
"modifier": ["LSHIFT"],
"decimal": 56
},
"[": {
"modifier": ["NONE"],
"decimal": 45
},
"\"": {
"modifier": ["LSHIFT"],
"decimal": 20
},
"\\": {
"modifier": ["NONE"],
"decimal": 49
},
"]": {
"modifier": ["NONE"],
"decimal": 46
},
"^": {
"modifier": ["LSHIFT"],
"decimal": 35
},
"_": {
"modifier": ["LSHIFT"],
"decimal": 52
},
"`": {
"modifier": ["NONE"],
"decimal": 53
},
"a": {
"modifier": ["NONE"],
"decimal": 4
},
"b": {
"modifier": ["NONE"],
"decimal": 17
},
"c": {
"modifier": ["NONE"],
"decimal": 12
},
"d": {
"modifier": ["NONE"],
"decimal": 11
},
"e": {
"modifier": ["NONE"],
"decimal": 7
},
"f": {
"modifier": ["NONE"],
"decimal": 28
@ -283,14 +123,170 @@
"modifier": ["NONE"],
"decimal": 24
},
"h": {
"c": {
"modifier": ["NONE"],
"decimal": 13
"decimal": 12
},
"r": {
"modifier": ["NONE"],
"decimal": 18
},
"l": {
"modifier": ["NONE"],
"decimal": 19
},
"/": {
"modifier": ["NONE"],
"decimal": 47
},
"=": {
"modifier": ["NONE"],
"decimal": 48
},
"\"": {
"modifier": ["LSHIFT"],
"decimal": 20
},
"<": {
"modifier": ["LSHIFT"],
"decimal": 26
},
">": {
"modifier": ["LSHIFT"],
"decimal": 8
},
"P": {
"modifier": ["LSHIFT"],
"decimal": 21
},
"Y": {
"modifier": ["LSHIFT"],
"decimal": 23
},
"F": {
"modifier": ["LSHIFT"],
"decimal": 28
},
"G": {
"modifier": ["LSHIFT"],
"decimal": 24
},
"C": {
"modifier": ["LSHIFT"],
"decimal": 12
},
"R": {
"modifier": ["LSHIFT"],
"decimal": 18
},
"L": {
"modifier": ["LSHIFT"],
"decimal": 19
},
"?": {
"modifier": ["LSHIFT"],
"decimal": 47
},
"+": {
"modifier": ["LSHIFT"],
"decimal": 48
},
"a": {
"modifier": ["NONE"],
"decimal": 4
},
"o": {
"modifier": ["NONE"],
"decimal": 22
},
"e": {
"modifier": ["NONE"],
"decimal": 7
},
"u": {
"modifier": ["NONE"],
"decimal": 9
},
"i": {
"modifier": ["NONE"],
"decimal": 10
},
"d": {
"modifier": ["NONE"],
"decimal": 11
},
"h": {
"modifier": ["NONE"],
"decimal": 13
},
"t": {
"modifier": ["NONE"],
"decimal": 14
},
"n": {
"modifier": ["NONE"],
"decimal": 15
},
"s": {
"modifier": ["NONE"],
"decimal": 51
},
"-": {
"modifier": ["NONE"],
"decimal": 52
},
"A": {
"modifier": ["LSHIFT"],
"decimal": 4
},
"O": {
"modifier": ["LSHIFT"],
"decimal": 22
},
"E": {
"modifier": ["LSHIFT"],
"decimal": 7
},
"U": {
"modifier": ["LSHIFT"],
"decimal": 9
},
"I": {
"modifier": ["LSHIFT"],
"decimal": 10
},
"D": {
"modifier": ["LSHIFT"],
"decimal": 11
},
"H": {
"modifier": ["LSHIFT"],
"decimal": 13
},
"T": {
"modifier": ["LSHIFT"],
"decimal": 14
},
"N": {
"modifier": ["LSHIFT"],
"decimal": 15
},
"S": {
"modifier": ["LSHIFT"],
"decimal": 51
},
"_": {
"modifier": ["LSHIFT"],
"decimal": 52
},
";": {
"modifier": ["NONE"],
"decimal": 29
},
"q": {
"modifier": ["NONE"],
"decimal": 27
},
"j": {
"modifier": ["NONE"],
"decimal": 6
@ -299,77 +295,81 @@
"modifier": ["NONE"],
"decimal": 25
},
"l": {
"x": {
"modifier": ["NONE"],
"decimal": 19
"decimal": 5
},
"b": {
"modifier": ["NONE"],
"decimal": 17
},
"m": {
"modifier": ["NONE"],
"decimal": 16
},
"n": {
"w": {
"modifier": ["NONE"],
"decimal": 15
},
"o": {
"modifier": ["NONE"],
"decimal": 22
},
"p": {
"modifier": ["NONE"],
"decimal": 21
},
"q": {
"modifier": ["NONE"],
"decimal": 27
},
"r": {
"modifier": ["NONE"],
"decimal": 18
},
"s": {
"modifier": ["NONE"],
"decimal": 51
},
"t": {
"modifier": ["NONE"],
"decimal": 14
},
"u": {
"modifier": ["NONE"],
"decimal": 9
"decimal": 54
},
"v": {
"modifier": ["NONE"],
"decimal": 55
},
"w": {
"modifier": ["NONE"],
"decimal": 54
},
"x": {
"modifier": ["NONE"],
"decimal": 5
},
"y": {
"modifier": ["NONE"],
"decimal": 23
},
"z": {
"modifier": ["NONE"],
"decimal": 56
},
"{": {
":": {
"modifier": ["LSHIFT"],
"decimal": 45
"decimal": 29
},
"Q": {
"modifier": ["LSHIFT"],
"decimal": 27
},
"J": {
"modifier": ["LSHIFT"],
"decimal": 6
},
"K": {
"modifier": ["LSHIFT"],
"decimal": 25
},
"X": {
"modifier": ["LSHIFT"],
"decimal": 5
},
"B": {
"modifier": ["LSHIFT"],
"decimal": 17
},
"M": {
"modifier": ["LSHIFT"],
"decimal": 16
},
"W": {
"modifier": ["LSHIFT"],
"decimal": 54
},
"V": {
"modifier": ["LSHIFT"],
"decimal": 55
},
"Z": {
"modifier": ["LSHIFT"],
"decimal": 56
},
"\\": {
"modifier": ["NONE"],
"decimal": 49
},
"|": {
"modifier": ["LSHIFT"],
"decimal": 49
},
"}": {
"modifier": ["LSHIFT"],
"decimal": 46
"`": {
"modifier": ["NONE"],
"decimal": 53
},
"~": {
"modifier": ["LSHIFT"],
@ -387,6 +387,96 @@
"modifier": ["NONE"],
"decimal": 44
},
"⎋": {
"modifier": [""],
"decimal": 41,
"PressDelayDelimiter": false
},
"↘": {
"modifier": [""],
"decimal": 77,
"PressDelayDelimiter": false
},
"↖": {
"modifier": [""],
"decimal": 74,
"PressDelayDelimiter": false
},
"⇪": {
"modifier": [""],
"decimal": 57,
"PressDelayDelimiter": false
},
"⌃": {
"modifier": ["LCTRL"],
"decimal": 0,
"PressDelayDelimiter": false
},
"⇧": {
"modifier": ["LSHIFT"],
"decimal": 0,
"PressDelayDelimiter": false
},
"⌥": {
"modifier": ["LALT"],
"decimal": 0,
"PressDelayDelimiter": false
},
"⌘": {
"modifier": ["LSUPER"],
"decimal": 0,
"PressDelayDelimiter": false
},
"⊞": {
"modifier": ["LSUPER"],
"decimal": 0,
"PressDelayDelimiter": false
},
"→": {
"modifier": [""],
"decimal": 79,
"PressDelayDelimiter": false
},
"←": {
"modifier": [""],
"decimal": 80,
"PressDelayDelimiter": false
},
"↑": {
"modifier": [""],
"decimal": 81,
"PressDelayDelimiter": false
},
"↓": {
"modifier": [""],
"decimal": 82,
"PressDelayDelimiter": false
},
"⇞": {
"modifier": [""],
"decimal": 75,
"PressDelayDelimiter": false
},
"⇟": {
"modifier": [""],
"decimal": 78,
"PressDelayDelimiter": false
},
"⌫": {
"modifier": [""],
"decimal": 42,
"PressDelayDelimiter": false
},
"⌦": {
"modifier": [""],
"decimal": 76,
"PressDelayDelimiter": false
},
"␀": {
"modifier": [""],
"decimal": 0,
"PressDelayDelimiter": false
},
"⏲": {
"modifier": ["NONE"],
"decimal": 0,

View File

@ -387,6 +387,101 @@
"modifier": ["NONE"],
"decimal": 44
},
"␛": {
"modifier": [""],
"decimal": 41,
"PressDelayDelimiter": false
},
"⎋": {
"modifier": [""],
"decimal": 41,
"PressDelayDelimiter": false
},
"↘": {
"modifier": [""],
"decimal": 77,
"PressDelayDelimiter": false
},
"↖": {
"modifier": [""],
"decimal": 74,
"PressDelayDelimiter": false
},
"⇪": {
"modifier": [""],
"decimal": 57,
"PressDelayDelimiter": false
},
"⌃": {
"modifier": ["LCTRL"],
"decimal": 0,
"PressDelayDelimiter": false
},
"⇧": {
"modifier": ["LSHIFT"],
"decimal": 0,
"PressDelayDelimiter": false
},
"⌥": {
"modifier": ["LALT"],
"decimal": 0,
"PressDelayDelimiter": false
},
"⌘": {
"modifier": ["LSUPER"],
"decimal": 0,
"PressDelayDelimiter": false
},
"⊞": {
"modifier": ["LSUPER"],
"decimal": 0,
"PressDelayDelimiter": false
},
"→": {
"modifier": [""],
"decimal": 79,
"PressDelayDelimiter": false
},
"←": {
"modifier": [""],
"decimal": 80,
"PressDelayDelimiter": false
},
"↑": {
"modifier": [""],
"decimal": 81,
"PressDelayDelimiter": false
},
"↓": {
"modifier": [""],
"decimal": 82,
"PressDelayDelimiter": false
},
"⇞": {
"modifier": [""],
"decimal": 75,
"PressDelayDelimiter": false
},
"⇟": {
"modifier": [""],
"decimal": 78,
"PressDelayDelimiter": false
},
"⌫": {
"modifier": [""],
"decimal": 42,
"PressDelayDelimiter": false
},
"⌦": {
"modifier": [""],
"decimal": 76,
"PressDelayDelimiter": false
},
"␀": {
"modifier": [""],
"decimal": 0,
"PressDelayDelimiter": false
},
"⏲": {
"modifier": ["NONE"],
"decimal": 0,

View File

@ -1,297 +1,377 @@
{
"": {
"modifier": ["NONE"],
"decimal": 30
},
"": {
"modifier": ["NONE"],
"decimal": 31
},
"": {
"modifier": ["NONE"],
"decimal": 32
},
"": {
"modifier": ["NONE"],
"decimal": 33
},
"": {
"modifier": ["NONE"],
"decimal": 34
},
"": {
"modifier": ["NONE"],
"decimal": 35
},
"": {
"modifier": ["NONE"],
"decimal": 36
},
"": {
"modifier": ["NONE"],
"decimal": 37
},
"": {
"modifier": ["NONE"],
"decimal": 38
},
"": {
"modifier": ["NONE"],
"decimal": 39
},
"": {
"modifier": ["NONE"],
"decimal": 45
},
"": {
"modifier": ["NONE"],
"decimal": 46
},
"": {
"modifier": ["LSHIFT"],
"decimal": 30
},
"": {
"modifier": ["LSHIFT"],
"decimal": 31
},
"": {
"modifier": ["LSHIFT"],
"decimal": 32
},
"": {
"modifier": ["LSHIFT"],
"decimal": 33
},
"": {
"modifier": ["LSHIFT"],
"decimal": 34
},
"": {
"modifier": ["LSHIFT"],
"decimal": 35
},
"": {
"modifier": ["LSHIFT"],
"decimal": 36
},
"*": {
"modifier": ["LSHIFT"],
"decimal": 37
},
"(": {
"modifier": ["LSHIFT"],
"decimal": 38
},
")": {
"modifier": ["LSHIFT"],
"decimal": 39
},
"": {
"modifier": ["LSHIFT"],
"decimal": 45
},
"": {
"modifier": ["LSHIFT"],
"decimal": 46
},
"": {
"modifier": ["NONE"],
"decimal": 20
},
"": {
"modifier": ["NONE"],
"decimal": 26
},
"": {
"modifier": ["NONE"],
"decimal": 8
},
"": {
"modifier": ["NONE"],
"decimal": 21
},
"": {
"modifier": ["NONE"],
"decimal": 23
},
"": {
"modifier": ["NONE"],
"decimal": 28
},
"": {
"modifier": ["NONE"],
"decimal": 24
},
"": {
"modifier": ["NONE"],
"decimal": 12
},
"": {
"modifier": ["NONE"],
"decimal": 18
},
"": {
"modifier": ["NONE"],
"decimal": 19
},
"": {
"modifier": ["NONE"],
"decimal": 47
},
"": {
"modifier": ["NONE"],
"decimal": 48
},
"": {
"modifier": ["LSHIFT"],
"decimal": 20
},
"": {
"modifier": ["LSHIFT"],
"decimal": 26
},
"": {
"modifier": ["LSHIFT"],
"decimal": 8
},
"": {
"modifier": ["LSHIFT"],
"decimal": 21
},
"": {
"modifier": ["LSHIFT"],
"decimal": 23
},
"": {
"modifier": ["LSHIFT"],
"decimal": 28
},
"": {
"modifier": ["LSHIFT"],
"decimal": 24
},
"I": {
"modifier": ["LSHIFT"],
"decimal": 12
},
"": {
"modifier": ["LSHIFT"],
"decimal": 18
},
"": {
"modifier": ["NONE"],
"decimal": 4
},
"": {
"modifier": ["NONE"],
"decimal": 22
},
"": {
"modifier": ["NONE"],
"decimal": 7
},
"": {
"modifier": ["NONE"],
"decimal": 9
},
"": {
"modifier": ["NONE"],
"decimal": 10
},
"": {
"modifier": ["NONE"],
"decimal": 11
},
"": {
"modifier": ["NONE"],
"decimal": 13
},
"": {
"modifier": ["NONE"],
"decimal": 14
},
"": {
"modifier": ["NONE"],
"decimal": 15
},
"": {
"modifier": ["NONE"],
"decimal": 51
},
"": {
"modifier": ["NONE"],
"decimal": 52
},
"": {
"modifier": ["LSHIFT"],
"decimal": 4
},
"": {
"modifier": ["LSHIFT"],
"decimal": 22
},
"": {
"modifier": ["LSHIFT"],
"decimal": 15
},
"": {
"modifier": ["NONE"],
"decimal": 29
"decimal": 30
},
"": {
"modifier": ["NONE"],
"decimal": 27
"decimal": 31
},
"": {
"modifier": ["NONE"],
"decimal": 6
"decimal": 32
},
"": {
"modifier": ["NONE"],
"decimal": 25
"decimal": 33
},
"": {
"modifier": ["NONE"],
"decimal": 5
"decimal": 34
},
"": {
"modifier": ["NONE"],
"decimal": 17
"decimal": 35
},
"": {
"modifier": ["NONE"],
"decimal": 16
"decimal": 36
},
"": {
"modifier": ["NONE"],
"decimal": 54
"decimal": 37
},
"": {
"modifier": ["NONE"],
"decimal": 38
},
"": {
"modifier": ["NONE"],
"decimal": 39
},
"": {
"modifier": ["NONE"],
"decimal": 45
},
"": {
"modifier": ["NONE"],
"decimal": 46
},
"": {
"modifier": ["LSHIFT"],
"decimal": 30
},
"": {
"modifier": ["LSHIFT"],
"decimal": 31
},
"": {
"modifier": ["LSHIFT"],
"decimal": 32
},
"": {
"modifier": ["LSHIFT"],
"decimal": 33
},
"": {
"modifier": ["LSHIFT"],
"decimal": 34
},
"": {
"modifier": ["LSHIFT"],
"decimal": 35
},
"": {
"modifier": ["LSHIFT"],
"decimal": 36
},
"": {
"modifier": ["LSHIFT"],
"decimal": 37
},
"": {
"modifier": ["LSHIFT"],
"decimal": 38
},
"": {
"modifier": ["LSHIFT"],
"decimal": 39
},
"": {
"modifier": ["LSHIFT"],
"decimal": 45
},
"": {
"modifier": ["LSHIFT"],
"decimal": 46
},
"": {
"modifier": ["NONE"],
"decimal": 20
},
"": {
"modifier": ["NONE"],
"decimal": 26
},
"": {
"modifier": ["NONE"],
"decimal": 8
},
"": {
"modifier": ["NONE"],
"decimal": 21
},
"": {
"modifier": ["NONE"],
"decimal": 23
},
"": {
"modifier": ["NONE"],
"decimal": 28
},
"": {
"modifier": ["NONE"],
"decimal": 24
},
"": {
"modifier": ["NONE"],
"decimal": 12
},
"": {
"modifier": ["NONE"],
"decimal": 18
},
"": {
"modifier": ["NONE"],
"decimal": 19
},
"": {
"modifier": ["NONE"],
"decimal": 47
},
"": {
"modifier": ["NONE"],
"decimal": 48
},
"": {
"modifier": ["LSHIFT"],
"decimal": 20
},
"": {
"modifier": ["LSHIFT"],
"decimal": 26
},
"": {
"modifier": ["LSHIFT"],
"decimal": 8
},
"": {
"modifier": ["LSHIFT"],
"decimal": 21
},
"": {
"modifier": ["LSHIFT"],
"decimal": 23
},
"": {
"modifier": ["LSHIFT"],
"decimal": 28
},
"": {
"modifier": ["LSHIFT"],
"decimal": 24
},
"": {
"modifier": ["LSHIFT"],
"decimal": 12
},
"": {
"modifier": ["LSHIFT"],
"decimal": 18
},
"": {
"modifier": ["LSHIFT"],
"decimal": 19
},
"": {
"modifier": ["LSHIFT"],
"decimal": 47
},
"": {
"modifier": ["LSHIFT"],
"decimal": 48
},
"": {
"modifier": ["NONE"],
"decimal": 4
},
"": {
"modifier": ["NONE"],
"decimal": 22
},
"": {
"modifier": ["NONE"],
"decimal": 7
},
"": {
"modifier": ["NONE"],
"decimal": 9
},
"": {
"modifier": ["NONE"],
"decimal": 10
},
"": {
"modifier": ["NONE"],
"decimal": 11
},
"": {
"modifier": ["NONE"],
"decimal": 13
},
"": {
"modifier": ["NONE"],
"decimal": 14
},
"": {
"modifier": ["NONE"],
"decimal": 15
},
"": {
"modifier": ["NONE"],
"decimal": 51
},
"": {
"modifier": ["NONE"],
"decimal": 52
},
"": {
"modifier": ["LSHIFT"],
"decimal": 4
},
"": {
"modifier": ["LSHIFT"],
"decimal": 22
},
"": {
"modifier": ["LSHIFT"],
"decimal": 7
},
"": {
"modifier": ["LSHIFT"],
"decimal": 9
},
"": {
"modifier": ["LSHIFT"],
"decimal": 10
},
"": {
"modifier": ["LSHIFT"],
"decimal": 11
},
"": {
"modifier": ["LSHIFT"],
"decimal": 13
},
"": {
"modifier": ["LSHIFT"],
"decimal": 14
},
"": {
"modifier": ["LSHIFT"],
"decimal": 15
},
"": {
"modifier": ["LSHIFT"],
"decimal": 51
},
"": {
"modifier": ["LSHIFT"],
"decimal": 52
},
"": {
"modifier": ["NONE"],
"decimal": 29
},
"": {
"modifier": ["NONE"],
"decimal": 27
},
"": {
"modifier": ["NONE"],
"decimal": 6
},
"": {
"modifier": ["NONE"],
"decimal": 25
},
"": {
"modifier": ["NONE"],
"decimal": 5
},
"": {
"modifier": ["NONE"],
"decimal": 17
},
"": {
"modifier": ["NONE"],
"decimal": 16
},
"": {
"modifier": ["NONE"],
"decimal": 54
},
"": {
"modifier": ["NONE"],
"decimal": 55
},
"": {
"": {
"modifier": ["NONE"],
"decimal": 56
},
"": {
"modifier": ["LSHIFT"],
"decimal": 29
},
"": {
"": {
"modifier": ["LSHIFT"],
"decimal": 27
},
"": {
"": {
"modifier": ["LSHIFT"],
"decimal": 6
},
"": {
"modifier": ["LSHIFT"],
"decimal": 25
},
"": {
"modifier": ["LSHIFT"],
"decimal": 5
},
"": {
"modifier": ["LSHIFT"],
"decimal": 17
},
"": {
"modifier": ["LSHIFT"],
"decimal": 16
},
"W": {
"modifier": ["LSHIFT"],
"decimal": 54
},
"": {
"modifier": ["LSHIFT"],
"decimal": 55
},
"": {
"modifier": ["NONE"],
"decimal": 49
"": {
"modifier": ["LSHIFT"],
"decimal": 56
},
"": {
"modifier": ["NONE"],
"decimal": 53
"decimal": 49
},
"": {
"modifier": ["LSHIFT"],
"decimal": 49
},
"\\": {
"modifier": ["NONE"],
"decimal": 53
},
"|": {
"modifier": ["LSHIFT"],
"decimal": 53
},
@ -307,6 +387,96 @@
"modifier": ["NONE"],
"decimal": 44
},
"⎋": {
"modifier": [""],
"decimal": 41,
"PressDelayDelimiter": false
},
"↘": {
"modifier": [""],
"decimal": 77,
"PressDelayDelimiter": false
},
"↖": {
"modifier": [""],
"decimal": 74,
"PressDelayDelimiter": false
},
"⇪": {
"modifier": [""],
"decimal": 57,
"PressDelayDelimiter": false
},
"⌃": {
"modifier": ["LCTRL"],
"decimal": 0,
"PressDelayDelimiter": false
},
"⇧": {
"modifier": ["LSHIFT"],
"decimal": 0,
"PressDelayDelimiter": false
},
"⌥": {
"modifier": ["LALT"],
"decimal": 0,
"PressDelayDelimiter": false
},
"⌘": {
"modifier": ["LSUPER"],
"decimal": 0,
"PressDelayDelimiter": false
},
"⊞": {
"modifier": ["LSUPER"],
"decimal": 0,
"PressDelayDelimiter": false
},
"→": {
"modifier": [""],
"decimal": 79,
"PressDelayDelimiter": false
},
"←": {
"modifier": [""],
"decimal": 80,
"PressDelayDelimiter": false
},
"↑": {
"modifier": [""],
"decimal": 81,
"PressDelayDelimiter": false
},
"↓": {
"modifier": [""],
"decimal": 82,
"PressDelayDelimiter": false
},
"⇞": {
"modifier": [""],
"decimal": 75,
"PressDelayDelimiter": false
},
"⇟": {
"modifier": [""],
"decimal": 78,
"PressDelayDelimiter": false
},
"⌫": {
"modifier": [""],
"decimal": 42,
"PressDelayDelimiter": false
},
"⌦": {
"modifier": [""],
"decimal": 76,
"PressDelayDelimiter": false
},
"␀": {
"modifier": [""],
"decimal": 0,
"PressDelayDelimiter": false
},
"⏲": {
"modifier": ["NONE"],
"decimal": 0,

View File

@ -375,6 +375,96 @@
"modifier": ["NONE"],
"decimal": 44
},
"⎋": {
"modifier": [""],
"decimal": 41,
"PressDelayDelimiter": false
},
"↘": {
"modifier": [""],
"decimal": 77,
"PressDelayDelimiter": false
},
"↖": {
"modifier": [""],
"decimal": 74,
"PressDelayDelimiter": false
},
"⇪": {
"modifier": [""],
"decimal": 57,
"PressDelayDelimiter": false
},
"⌃": {
"modifier": ["LCTRL"],
"decimal": 0,
"PressDelayDelimiter": false
},
"⇧": {
"modifier": ["LSHIFT"],
"decimal": 0,
"PressDelayDelimiter": false
},
"⌥": {
"modifier": ["LALT"],
"decimal": 0,
"PressDelayDelimiter": false
},
"⌘": {
"modifier": ["LSUPER"],
"decimal": 0,
"PressDelayDelimiter": false
},
"⊞": {
"modifier": ["LSUPER"],
"decimal": 0,
"PressDelayDelimiter": false
},
"→": {
"modifier": [""],
"decimal": 79,
"PressDelayDelimiter": false
},
"←": {
"modifier": [""],
"decimal": 80,
"PressDelayDelimiter": false
},
"↑": {
"modifier": [""],
"decimal": 81,
"PressDelayDelimiter": false
},
"↓": {
"modifier": [""],
"decimal": 82,
"PressDelayDelimiter": false
},
"⇞": {
"modifier": [""],
"decimal": 75,
"PressDelayDelimiter": false
},
"⇟": {
"modifier": [""],
"decimal": 78,
"PressDelayDelimiter": false
},
"⌫": {
"modifier": [""],
"decimal": 42,
"PressDelayDelimiter": false
},
"⌦": {
"modifier": [""],
"decimal": 76,
"PressDelayDelimiter": false
},
"␀": {
"modifier": [""],
"decimal": 0,
"PressDelayDelimiter": false
},
"⏲": {
"modifier": ["NONE"],
"decimal": 0,

View File

@ -559,6 +559,96 @@
"modifier": ["NONE"],
"decimal": 44
},
"⎋": {
"modifier": [""],
"decimal": 41,
"PressDelayDelimiter": false
},
"↘": {
"modifier": [""],
"decimal": 77,
"PressDelayDelimiter": false
},
"↖": {
"modifier": [""],
"decimal": 74,
"PressDelayDelimiter": false
},
"⇪": {
"modifier": [""],
"decimal": 57,
"PressDelayDelimiter": false
},
"⌃": {
"modifier": ["LCTRL"],
"decimal": 0,
"PressDelayDelimiter": false
},
"⇧": {
"modifier": ["LSHIFT"],
"decimal": 0,
"PressDelayDelimiter": false
},
"⌥": {
"modifier": ["LALT"],
"decimal": 0,
"PressDelayDelimiter": false
},
"⌘": {
"modifier": ["LSUPER"],
"decimal": 0,
"PressDelayDelimiter": false
},
"⊞": {
"modifier": ["LSUPER"],
"decimal": 0,
"PressDelayDelimiter": false
},
"→": {
"modifier": [""],
"decimal": 79,
"PressDelayDelimiter": false
},
"←": {
"modifier": [""],
"decimal": 80,
"PressDelayDelimiter": false
},
"↑": {
"modifier": [""],
"decimal": 81,
"PressDelayDelimiter": false
},
"↓": {
"modifier": [""],
"decimal": 82,
"PressDelayDelimiter": false
},
"⇞": {
"modifier": [""],
"decimal": 75,
"PressDelayDelimiter": false
},
"⇟": {
"modifier": [""],
"decimal": 78,
"PressDelayDelimiter": false
},
"⌫": {
"modifier": [""],
"decimal": 42,
"PressDelayDelimiter": false
},
"⌦": {
"modifier": [""],
"decimal": 76,
"PressDelayDelimiter": false
},
"␀": {
"modifier": [""],
"decimal": 0,
"PressDelayDelimiter": false
},
"⏲": {
"modifier": ["NONE"],
"decimal": 0,

124
main.go
View File

@ -3,34 +3,126 @@ package main
import (
"flag"
"fmt"
"io"
"os"
"path"
"strings"
"time"
"timmy.narnian.us/hid/ghid"
hid "gitea.narnian.us/lordwelch/hid/ghid"
)
func contains(str string, find []string) bool {
str = strings.ToLower(str)
for _, s := range find {
if strings.Contains(str, strings.ToLower(s)) {
return true
}
}
return false
}
func parse_shortcut(shortcut string) ([8]byte, error) {
var (
modifiers = []string{}
key = ""
curModifier byte = 0
curKey byte = 0
)
strs := strings.SplitN(strings.ToLower(shortcut), " ", 2)
if len(strs) > 1 {
modifiers = strings.Split(strs[0], "|")
key = strings.TrimSpace(strs[1])
} else {
if contains(strs[0], hid.AllModifiers) {
modifiers = strings.Split(strs[0], "|")
} else {
key = strings.TrimSpace(strs[0])
}
}
for _, v := range modifiers {
curModifier |= hid.Modifiers[strings.TrimSpace(v)]
}
if id, ok := hid.StandardKeys[key]; ok {
curKey = id
} else {
return [8]byte{}, fmt.Errorf("Key %q not found", key)
}
return [8]byte{curModifier, 0x0, curKey}, nil
}
func main() {
var (
SHORTCUT string
Shortcut string
filePath string
keymapPath string
ghidPath string
pressDelay time.Duration
releaseDelay time.Duration
err error
ghid *os.File
tmp *os.File
keyboard *hid.Keyboard
keymaps []string
)
flag.StringVar(&SHORTCUT, "shortcut", "", "Keymap cycle shortcut")
flag.StringVar(&SHORTCUT, "s", "", "Keymap cycle shortcut")
flag.StringVar(&hid.KeymapPath, "path", os.ExpandEnv("$XDG_CONFIG_HOME"), "Path to config dir default: $XDG_CONFIG_HOME")
flag.StringVar(&hid.KeymapPath, "p", os.ExpandEnv("$XDG_CONFIG_HOME"), "Path to config dir default: $XDG_CONFIG_HOME")
if _, exists := os.LookupEnv("XDG_CONFIG_HOME"); !exists {
_ = os.Setenv("XDG_CONFIG_HOME", path.Join(os.ExpandEnv("$HOME"), ".config"))
}
flag.StringVar(&Shortcut, "shortcut", "", "Keymap cycle shortcut")
flag.StringVar(&Shortcut, "s", "LALT ⇪", "Keymap cycle shortcut")
flag.StringVar(&keymapPath, "path", path.Join(os.ExpandEnv("$XDG_CONFIG_HOME"), "hid"), "Path to config dir default: $XDG_CONFIG_HOME")
flag.StringVar(&keymapPath, "p", path.Join(os.ExpandEnv("$XDG_CONFIG_HOME"), "hid"), "Path to config dir default: $XDG_CONFIG_HOME")
flag.StringVar(&filePath, "f", "-", "The file to read content from. Defaults to stdin")
flag.StringVar(&filePath, "file", "-", "The file to read content from. Defaults to stdin")
flag.StringVar(&ghidPath, "g", "/dev/hidg0", "The device to send key presses to. Defaults to /dev/hidg0")
flag.StringVar(&ghidPath, "ghid", "/dev/hidg0", "The device to send key presses to. Defaults to /dev/hidg0")
flag.DurationVar(&pressDelay, "press", 0, "sets the default delay between presses of individual keys")
flag.DurationVar(&releaseDelay, "release", 0, "sets the default delay between sending the press of an individual key and sending the release")
flag.Parse()
hid.KeymapOrder = flag.Args()
fmt.Println(hid.KeymapPath)
file, err := os.OpenFile("/dev/hidg0", os.O_APPEND|os.O_WRONLY, 0755)
if flag.NArg() < 0 {
flag.Usage()
os.Exit(1)
}
fmt.Println(keymapPath)
dirs, err := os.ReadDir(keymapPath)
if err != nil {
panic(err)
}
hid.Hidg0 = file
defer file.Close()
hid.Write(os.Stdin)
keymap:
for _, requestedKeymap := range flag.Args() {
for _, dir := range dirs {
if strings.HasPrefix(strings.ToLower(dir.Name()), strings.ToLower(requestedKeymap)) {
keymaps = append(keymaps, strings.TrimSuffix(dir.Name(), ".json"))
break keymap
}
}
panic(fmt.Sprintf("Keymap %q not found", requestedKeymap))
}
if filePath != "-" {
tmp, err = os.Open(path.Clean(filePath))
if err == nil {
_ = os.Stdin.Close()
os.Stdin = tmp
}
}
ghid, err = os.OpenFile(ghidPath, os.O_APPEND|os.O_WRONLY, 0600)
if err != nil {
panic(err)
}
defer ghid.Close()
keyboard = hid.NewKeyboard(hid.Modifiers, keymaps, keymapPath, ghid)
keyboard.PressDelay = pressDelay
keyboard.ReleaseDelay = releaseDelay
keyboard.KeymapShortcut, err = parse_shortcut(Shortcut)
if err != nil {
panic(fmt.Errorf("error parsing shortcut: %w", err))
}
_, err = io.Copy(keyboard, os.Stdin)
if err != nil {
panic(err)