diff options
author | Devaev Maxim <[email protected]> | 2021-05-20 04:22:32 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2021-05-20 04:22:32 +0300 |
commit | c0afe3ba40d0df88a95f7a330c5c00d4e298a629 (patch) | |
tree | facb52d367e058b3e456c7e1787b98709a92f0f5 /kvmd | |
parent | c1fcfdb6cef8d9a66b6d2f3a33348c08f271c6b4 (diff) |
pikvm/pikvm#306: replace quotes for hid print
Diffstat (limited to 'kvmd')
-rw-r--r-- | kvmd/keyboard/printer.py | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/kvmd/keyboard/printer.py b/kvmd/keyboard/printer.py index 3c73bd85..990aca21 100644 --- a/kvmd/keyboard/printer.py +++ b/kvmd/keyboard/printer.py @@ -29,7 +29,7 @@ from .mappings import WebModifiers # ===== -def text_to_web_keys( +def text_to_web_keys( # pylint: disable=too-many-branches text: str, symmap: Dict[int, Dict[int, str]], shift_key: str=WebModifiers.SHIFT_LEFT, @@ -39,18 +39,25 @@ def text_to_web_keys( shifted = False for ch in text: - try: - code = ord(ch) - 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: + # https://stackoverflow.com/questions/12343987/convert-ascii-character-to-x11-keycode + # https://www.ascii-code.com + if ch == "\n": + keys = {0: "Enter"} + elif ch == "\t": + keys = {0: "Tab"} + elif ch == " ": + keys = {0: "Space"} + else: + if ch in ["‚", "‘", "’"]: + ch = "'" + elif ch in ["„", "“", "”"]: + ch = "\"" + if not ch.isprintable(): + continue + try: + keys = symmap[ord(ch)] + except Exception: continue - except Exception: - continue for (modifiers, key) in reversed(keys.items()): if (modifiers & SymmapModifiers.ALTGR) or (modifiers & SymmapModifiers.CTRL): |