summaryrefslogtreecommitdiff
path: root/kvmd/plugins
diff options
context:
space:
mode:
authorjacobbar <[email protected]>2023-03-16 04:26:29 +0700
committerMaxim Devaev <[email protected]>2023-07-10 03:02:28 +0300
commit4220fe590839379ec67fa78c077c1d309cd5eb91 (patch)
tree5f258306cd0f487d51e4c4c25dbac3848d59e739 /kvmd/plugins
parent6689008840dca1a0d3587192d1087854b1d64e6e (diff)
fixes ch9329 plugin multiple keyboard keys (#123)
* Add ch9329 plugin --------- Co-authored-by: Maxim Devaev <[email protected]>
Diffstat (limited to 'kvmd/plugins')
-rw-r--r--kvmd/plugins/hid/ch9329/keyboard.py31
1 files changed, 20 insertions, 11 deletions
diff --git a/kvmd/plugins/hid/ch9329/keyboard.py b/kvmd/plugins/hid/ch9329/keyboard.py
index 70ccf547..cfbe3ece 100644
--- a/kvmd/plugins/hid/ch9329/keyboard.py
+++ b/kvmd/plugins/hid/ch9329/keyboard.py
@@ -33,14 +33,22 @@ class Keyboard:
"caps": False,
"scroll": False,
}, self.__notifier, type=bool)
-
- self.__active_keys: list[list] = []
+ self.__modifiers = 0x00
+ self.__active_keys: list[int] = []
def key(self, key: str, state: bool) -> list[int]:
+ modifier = self.__is_modifier(key)
+ code = self.__keycode(key)
+ if not state:
+ if not modifier and code in self.__active_keys:
+ self.__active_keys.remove(code)
+ if modifier and self.__modifiers:
+ self.__modifiers &= ~code
if state:
- self.__active_keys.append([key, self.__is_modifier(key)])
- else:
- self.__active_keys.remove([key, self.__is_modifier(key)])
+ if not modifier and len(self.__active_keys) < 6:
+ self.__active_keys.append(code)
+ if modifier:
+ self.__modifiers |= code
return self.__key()
async def leds(self) -> dict:
@@ -54,13 +62,14 @@ class Keyboard:
self.__leds.update(num=num, caps=caps, scroll=scroll)
def __key(self) -> list[int]:
- cmd = [0x00, 0x02, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
+ cmd = [
+ 0x00, 0x02, 0x08,
+ self.__modifiers,
+ 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
counter = 0
- for key in self.__active_keys:
- if key[1]:
- cmd[3 + counter] = self.__keycode(key[0])
- else:
- cmd[5 + counter] = self.__keycode(key[0])
+ for code in self.__active_keys:
+ cmd[5 + counter] = code
counter += 1
return cmd