summaryrefslogtreecommitdiff
path: root/kvmd/keyboard/printer.py
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2020-10-08 12:18:38 +0300
committerDevaev Maxim <[email protected]>2020-10-08 12:18:38 +0300
commitf1910f7c8ec085eece1adc56ff999527881e71d9 (patch)
tree4f3cb6c481a7d0f29b91fa8ccc9e320f3a29b73b /kvmd/keyboard/printer.py
parent920f648d6526217009f8ee4dc6e943a28a4886db (diff)
more correct keymap handling
Diffstat (limited to 'kvmd/keyboard/printer.py')
-rw-r--r--kvmd/keyboard/printer.py35
1 files changed, 21 insertions, 14 deletions
diff --git a/kvmd/keyboard/printer.py b/kvmd/keyboard/printer.py
index 2fb7d756..acef102b 100644
--- a/kvmd/keyboard/printer.py
+++ b/kvmd/keyboard/printer.py
@@ -24,13 +24,13 @@ from typing import Tuple
from typing import Dict
from typing import Generator
-from .keysym import SymmapWebKey
+from .keysym import SymmapModifiers
# =====
def text_to_web_keys(
text: str,
- symmap: Dict[int, SymmapWebKey],
+ symmap: Dict[int, Dict[int, str]],
shift_key: str="ShiftLeft",
) -> Generator[Tuple[str, bool], None, None]:
@@ -40,25 +40,32 @@ def text_to_web_keys(
for ch in text:
try:
code = ord(ch)
- if not (0x20 <= code <= 0x7E):
+ if 0x20 <= code <= 0x7E:
# https://stackoverflow.com/questions/12343987/convert-ascii-character-to-x11-keycode
# https://www.ascii-code.com
+ keys = symmap[code]
+ elif code == 0x0A: # Enter:
+ keys = {0: "Enter"}
+ else:
continue
- key = symmap[code]
except Exception:
continue
- if key.altgr or key.ctrl:
- continue # Not supported yet
- if key.shift and not shifted:
- yield (shift_key, True)
- shifted = True
- elif not key.shift and shifted:
- yield (shift_key, False)
- shifted = False
+ for (modifiers, key) in reversed(keys.items()):
+ if (modifiers & SymmapModifiers.ALTGR) or (modifiers & SymmapModifiers.CTRL):
+ # Not supported yet
+ continue
+
+ if modifiers & SymmapModifiers.SHIFT and not shifted:
+ yield (shift_key, True)
+ shifted = True
+ elif not (modifiers & SymmapModifiers.SHIFT) and shifted:
+ yield (shift_key, False)
+ shifted = False
- yield (key.name, True)
- yield (key.name, False)
+ yield (key, True)
+ yield (key, False)
+ break
if shifted:
yield (shift_key, False)