Remote: forward the physical keyboard and hide the phone OSK while typing
CI / test (push) Failing after 1m7s

The web UI now sends key events without opening the KB bar, and releases
held keys on blur, hide or disconnect. The first remote keystroke (web or
VNC) turns the on-screen keyboard off; it comes back when the last typing
client disconnects, unless the user toggled it by hand.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
nandiandClaude Opus 5.5 committed 2026-11-29 14:27:17 -08:00
1 parent 5e62f1b8cb
commit 0356413bb2
7 files changed
+411 -26

No files matched your search

+123
View File
@@ -236,6 +236,17 @@ class MockCtlServer:
elif cmd == "screen toggle":
self.screen = "off" if self.screen == "on" else "on"
rep = f"ok {self.screen}\n"
elif cmd == "osk status":
rep = f"ok {'on' if self.osk else 'off'}\n"
elif cmd == "osk off":
self.osk = 0
rep = "ok off\n"
elif cmd == "osk on":
self.osk = 1
rep = "ok on\n"
elif cmd == "osk toggle":
self.osk = 0 if self.osk else 1
rep = f"ok {'on' if self.osk else 'off'}\n"
else:
rep = "ok\n"
conn.sendall(rep.encode())
@@ -638,6 +649,118 @@ class RemoteTests(unittest.TestCase):
self.assertIn("101", status_line)
ws.close()
def test_06_web_keyboard_forwarding_release_and_osk_autosuppress(self):
self.shm.write_frame(160, 120, lambda x, y: (30, 80, 180))
self.start_daemon(auth="none")
c = http.client.HTTPConnection("127.0.0.1", self.web_port, timeout=5)
c.request("GET", "/")
r = c.getresponse()
self.assertEqual(r.status, 200)
html = r.read().decode("utf-8")
self.assertIn("window.addEventListener('keydown'", html)
c.close()
# Connect WebSocket and wait for initial status (osk=1)
ws, status_line, _, extra = ws_connect("127.0.0.1", self.web_port)
self.assertIn("101", status_line)
buf = bytearray(extra)
def read_next_status(sock, rxbuf, timeout=3.0):
deadline = time.time() + timeout
while time.time() < deadline:
op, payload = ws_read_frame(sock, rxbuf)
if op == 1:
return json.loads(payload)
raise TimeoutError("timed out waiting for status")
st0 = read_next_status(ws, buf)
self.assertEqual(st0["osk"], 1)
# Shifted letter, Ctrl+C, F5, Super, CapsLock, non-ASCII Unicode, and release
ws_send_text(ws, json.dumps({"t": "key", "k": 0xFFE1, "d": 1})) # Shift_L
ws_send_text(ws, json.dumps({"t": "key", "k": 0x0041, "d": 1})) # 'A'
ws_send_text(ws, json.dumps({"t": "key", "k": 0x0041, "d": 0}))
ws_send_text(ws, json.dumps({"t": "key", "k": 0xFFE1, "d": 0}))
# OSK should auto-suppress to 0 on first keystroke and push updated status
st1 = read_next_status(ws, buf)
self.assertEqual(st1["osk"], 0)
self.assertEqual(self.ctl.osk, 0)
ws_send_text(ws, json.dumps({"t": "key", "k": 0xFFE3, "d": 1})) # Control_L
ws_send_text(ws, json.dumps({"t": "key", "k": 0x0063, "d": 1})) # 'c'
ws_send_text(ws, json.dumps({"t": "key", "k": 0x0063, "d": 0}))
ws_send_text(ws, json.dumps({"t": "key", "k": 0xFFE3, "d": 0}))
ws_send_text(ws, json.dumps({"t": "key", "k": 0xFFC2, "d": 1})) # F5 (evdev 63)
ws_send_text(ws, json.dumps({"t": "key", "k": 0xFFC2, "d": 0}))
ws_send_text(ws, json.dumps({"t": "key", "k": 0xFFEB, "d": 1})) # Super_L (evdev 125, mod 64)
ws_send_text(ws, json.dumps({"t": "key", "k": 0xFFEB, "d": 0}))
ws_send_text(ws, json.dumps({"t": "key", "k": 0xFFE5, "d": 1})) # CapsLock (evdev 58, no depressed mod)
ws_send_text(ws, json.dumps({"t": "key", "k": 0xFFE5, "d": 0}))
ws_send_text(ws, json.dumps({"t": "key", "k": 0x00E9, "d": 1})) # Unicode 'é'
ws_send_text(ws, json.dumps({"t": "key", "k": 0x00E9, "d": 0}))
# Hold Shift_L + 'b' (evdev 48) and test release clearing both
ws_send_text(ws, json.dumps({"t": "key", "k": 0xFFE1, "d": 1}))
ws_send_text(ws, json.dumps({"t": "key", "k": 0x0062, "d": 1}))
ws_send_text(ws, json.dumps({"t": "release"}))
time.sleep(0.2)
cmds = self.ctl.commands
joined = "\n".join(cmds)
self.assertIn("osk status", joined)
self.assertIn("osk off", joined)
self.assertIn("input-mods 1 0 0 0", joined)
self.assertIn("input-key 30 1", joined)
self.assertIn("input-mods 4 0 0 0", joined)
self.assertIn("input-key 46 1", joined)
self.assertIn("input-key 63 1", joined)
self.assertIn("input-mods 64 0 0 0", joined)
self.assertIn("input-key 125 1", joined)
self.assertIn("input-key 58 1", joined)
self.assertIn("input-key 58 0", joined)
self.assertNotIn("input-mods 2 0 0 0", joined)
self.assertIn("input-text c3a9", joined)
# Release cleared stuck 'b' (48), Shift_L (42), and depressed mods
rel_idx = len(cmds) - 1 - cmds[::-1].index("input-key 48 0")
tail = "\n".join(cmds[rel_idx:])
self.assertIn("input-key 48 0", tail)
self.assertIn("input-key 42 0", tail)
self.assertIn("input-mods 0 0 0 0", tail)
ws.close()
deadline = time.time() + 3.0
while time.time() < deadline and self.ctl.osk != 1:
time.sleep(0.05)
self.assertEqual(self.ctl.osk, 1)
# Manual override: explicit `ctl: "osk on"` stays on across later keystrokes & disconnect
ws2, status_line2, _, extra2 = ws_connect("127.0.0.1", self.web_port)
self.assertIn("101", status_line2)
buf2 = bytearray(extra2)
_ = read_next_status(ws2, buf2)
ws_send_text(ws2, json.dumps({"t": "key", "k": 0x0061, "d": 1}))
ws_send_text(ws2, json.dumps({"t": "key", "k": 0x0061, "d": 0}))
self.assertEqual(read_next_status(ws2, buf2)["osk"], 0)
self.assertEqual(self.ctl.osk, 0)
ws_send_text(ws2, json.dumps({"t": "ctl", "cmd": "osk on"}))
self.assertEqual(read_next_status(ws2, buf2)["osk"], 1)
self.assertEqual(self.ctl.osk, 1)
ws_send_text(ws2, json.dumps({"t": "key", "k": 0x0062, "d": 1}))
ws_send_text(ws2, json.dumps({"t": "key", "k": 0x0062, "d": 0}))
time.sleep(0.15)
self.assertEqual(self.ctl.osk, 1)
ws2.close()
time.sleep(0.15)
self.assertEqual(self.ctl.osk, 1)
if __name__ == "__main__":
unittest.main()