summaryrefslogtreecommitdiff
path: root/kvmd/plugins/hid/otg/keyboard.py
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2020-02-08 03:34:43 +0300
committerDevaev Maxim <[email protected]>2020-02-08 03:34:43 +0300
commit635cfc7d9e3b57eee608c34f789ed6a7bfec8962 (patch)
treefacabdb816f6d302188d859e49c8a825241aabd0 /kvmd/plugins/hid/otg/keyboard.py
parent301e58148e5b2140e2a9e96dbaa04b27d6bd8b6e (diff)
fixed hid ensuring
Diffstat (limited to 'kvmd/plugins/hid/otg/keyboard.py')
-rw-r--r--kvmd/plugins/hid/otg/keyboard.py44
1 files changed, 19 insertions, 25 deletions
diff --git a/kvmd/plugins/hid/otg/keyboard.py b/kvmd/plugins/hid/otg/keyboard.py
index fab7b992..6cf8f72d 100644
--- a/kvmd/plugins/hid/otg/keyboard.py
+++ b/kvmd/plugins/hid/otg/keyboard.py
@@ -73,11 +73,7 @@ class KeyboardProcess(BaseDeviceProcess):
def cleanup(self) -> None:
self._stop()
get_logger().info("Clearing HID-keyboard events ...")
- if self._ensure_device():
- try:
- self._write_report(b"\x00" * 8) # Release all keys and modifiers
- finally:
- self._close_device()
+ self._ensure_write(b"\x00" * 8, close=True) # Release all keys and modifiers
def send_clear_event(self) -> None:
self._queue_event(_ClearEvent())
@@ -107,9 +103,7 @@ class KeyboardProcess(BaseDeviceProcess):
def __process_clear_event(self, reopen: bool=False) -> None:
self.__clear_modifiers()
self.__clear_keys()
- if reopen:
- self._close_device()
- self.__send_current_state()
+ self.__send_current_state(reopen=reopen)
def __process_modifier_event(self, event: _ModifierEvent) -> None:
if event.modifier in self.__pressed_modifiers:
@@ -140,28 +134,28 @@ class KeyboardProcess(BaseDeviceProcess):
# =====
- def __send_current_state(self) -> bool:
- ok = False
- if self._ensure_device():
- modifiers = 0
- for modifier in self.__pressed_modifiers:
- modifiers |= modifier.code
-
- assert len(self.__pressed_keys) == 6
- keys = [
- (0 if key is None else key.code)
- for key in self.__pressed_keys
- ]
-
- ok = self._write_report(bytes([modifiers, 0] + keys))
-
- if not ok:
+ def __send_current_state(self, reopen: bool=False) -> bool:
+ if not self._ensure_write(self.__make_report(), reopen=reopen):
self.__clear_modifiers()
self.__clear_keys()
- return ok
+ return False
+ return True
def __clear_modifiers(self) -> None:
self.__pressed_modifiers.clear()
def __clear_keys(self) -> None:
self.__pressed_keys = [None] * 6
+
+ def __make_report(self) -> bytes:
+ modifiers = 0
+ for modifier in self.__pressed_modifiers:
+ modifiers |= modifier.code
+
+ assert len(self.__pressed_keys) == 6
+ keys = [
+ (0 if key is None else key.code)
+ for key in self.__pressed_keys
+ ]
+
+ return bytes([modifiers, 0] + keys)