First version

This commit is contained in:
andy committed 2026-10-15 20:44:05 -03:00
commit 243e92a9dd
84 files changed
+4012

No files matched your search

Executable
+36
View File
@@ -0,0 +1,36 @@
#!/usr/bin/env python3
# Types text into the VM through the QEMU monitor (US keyboard).
# Usage: type.py MONITOR_SOCKET 'text' (newline = Enter; keys: {{ctrl-s}}, {{esc}}, ...)
import re, socket, sys, time
SHIFTED = {'!': '1', '@': '2', '#': '3', '$': '4', '%': '5', '^': '6', '&': '7', '*': '8',
'(': '9', ')': '0', '_': 'minus', '+': 'equal', '{': 'bracket_left',
'}': 'bracket_right', '|': 'backslash', ':': 'semicolon', '"': 'apostrophe',
'<': 'comma', '>': 'dot', '?': 'slash', '~': 'grave_accent'}
PLAIN = {' ': 'spc', '\n': 'ret', '\t': 'tab', '-': 'minus', '=': 'equal', '[': 'bracket_left',
']': 'bracket_right', '\\': 'backslash', ';': 'semicolon', "'": 'apostrophe',
',': 'comma', '.': 'dot', '/': 'slash', '`': 'grave_accent'}
def keys(text):
for token in re.split(r'(\{\{[a-z0-9_-]+\}\})', text):
if token.startswith('{{') and token.endswith('}}'):
yield token[2:-2]
continue
for c in token:
if c in PLAIN:
yield PLAIN[c]
elif c in SHIFTED:
yield 'shift-' + SHIFTED[c]
elif c.isupper():
yield 'shift-' + c.lower()
elif c.isalnum():
yield c
s = socket.socket(socket.AF_UNIX)
s.connect(sys.argv[1])
time.sleep(0.2)
text = open(sys.argv[2][1:]).read() if sys.argv[2].startswith('@') else sys.argv[2]
for k in keys(text):
s.sendall(('sendkey %s\n' % k).encode())
time.sleep(0.06)
time.sleep(0.3)