Add support for modifier keys (eg CTRL+D, CTRL+SHIFT+D)

This commit is contained in:
lordwelch 2021-02-26 12:32:23 -08:00
parent 7244a85ecd
commit a594b3044c
6 changed files with 473 additions and 4 deletions

View File

@ -137,6 +137,10 @@ func (k *Keyboard) Write(p []byte) (int, error) {
}
index += s + n
break press
case r == '␀':
// Causes immediate key press useful for modifier keys
index += s
break press
default:
// Calculate next modifier byte
@ -149,12 +153,18 @@ func (k *Keyboard) Write(p []byte) (int, 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
fmt.Printf("this press is modified %d %v\n", flag, cur)
}
// 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
}
}
@ -162,7 +172,11 @@ func (k *Keyboard) Write(p []byte) (int, error) {
report[i] = cur.Decimal
index += s
if k.PressDelay > 0 {
break press
// 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
}
fmt.Printf("this press is a modifier %v\n", cur)
}
}
report[0] = flag

View File

@ -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

@ -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

@ -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,