pikvm/pikvm#306: replace quotes for hid print

This commit is contained in:
Devaev Maxim 2021-05-20 04:22:32 +03:00
parent c1fcfdb6ce
commit c0afe3ba40

View File

@ -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, text: str,
symmap: Dict[int, Dict[int, str]], symmap: Dict[int, Dict[int, str]],
shift_key: str=WebModifiers.SHIFT_LEFT, shift_key: str=WebModifiers.SHIFT_LEFT,
@ -39,16 +39,23 @@ def text_to_web_keys(
shifted = False shifted = False
for ch in text: for ch in text:
try:
code = ord(ch)
if 0x20 <= code <= 0x7E:
# https://stackoverflow.com/questions/12343987/convert-ascii-character-to-x11-keycode # https://stackoverflow.com/questions/12343987/convert-ascii-character-to-x11-keycode
# https://www.ascii-code.com # https://www.ascii-code.com
keys = symmap[code] if ch == "\n":
elif code == 0x0A: # Enter:
keys = {0: "Enter"} keys = {0: "Enter"}
elif ch == "\t":
keys = {0: "Tab"}
elif ch == " ":
keys = {0: "Space"}
else: else:
if ch in ["", "", ""]:
ch = "'"
elif ch in ["", "", ""]:
ch = "\""
if not ch.isprintable():
continue continue
try:
keys = symmap[ord(ch)]
except Exception: except Exception:
continue continue