This is a projection, not a development branch. The tree above was constructed from the internal source named below under a manifest that decides which paths may leave, then scanned as a whole tree rather than as a series of patches, and only then published. Public history starts here because the history before it was not admissible, and neither was the tree. What used to stand in this repository included a rescue copy of another machine, a directory of phone handoffs, deployment wired to one house, and a submodule pointing at a forge no stranger can reach. None of that was ever the product. It stays in the private forge, which is allowed to hold the whole working organism, and this is what was deliberately sent out instead. Three mechanisms produced this tree, in decreasing order of trust. A top-level path the manifest does not name never arrives at all, which is the one that catches directories nobody has thought of yet. Named internal files inside admitted roots are dropped. A short, reviewed table replaces deployment defaults that a public build must not carry -- an endpoint aimed at one LAN, a VPN profile belonging to one phone, packaging built from one checkout path. Everything after this commit is an ordinary publication with the same three trailers, so a force push stops being routine and starts meaning that something deliberate happened. The trailers bind the projection to its source without pretending the public SHA is the private one: same lineage, different tree, and the record says so. Source-Sha: 8f27b1e76a8fef560a336aba18e6990713ff1047 Policy-Sha: 6b261d2f3e6e1fb19874846ba4bb1dfe15565d25b8618c1c1afba0419c101d27 Tree-Digest: 18ec3563c5e5ef9a414993a9f6734b251ff9ed3cd56eebdd6cac01e45c6e3067
80 lines
2.3 KiB
Python
Executable file
80 lines
2.3 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
"""Monitor physical keyboard events via evdev and output JSON lines to stdout."""
|
|
|
|
import glob
|
|
import json
|
|
import os
|
|
import select
|
|
import struct
|
|
import sys
|
|
|
|
# Linux input event format: struct input_event { timeval time; __u16 type; __u16 code; __s32 value; }
|
|
# On 64-bit: timeval is 16 bytes (tv_sec: 8, tv_usec: 8), total = 24 bytes
|
|
EVENT_FORMAT = "llHHI"
|
|
EVENT_SIZE = struct.calcsize(EVENT_FORMAT)
|
|
EV_KEY = 1
|
|
|
|
|
|
def find_keyboard_devices():
|
|
"""Find keyboard event devices via /dev/input/by-path."""
|
|
seen = set()
|
|
devices = []
|
|
for path in sorted(glob.glob("/dev/input/by-path/*-event-kbd")):
|
|
real = os.path.realpath(path)
|
|
if real not in seen:
|
|
seen.add(real)
|
|
devices.append(real)
|
|
return devices
|
|
|
|
|
|
def emit(obj):
|
|
sys.stdout.write(json.dumps(obj) + "\n")
|
|
sys.stdout.flush()
|
|
|
|
|
|
def main():
|
|
devices = find_keyboard_devices()
|
|
if not devices:
|
|
emit({"error": "No keyboard devices found"})
|
|
return 1
|
|
|
|
fds = {}
|
|
for dev_path in devices:
|
|
try:
|
|
fd = os.open(dev_path, os.O_RDONLY | os.O_NONBLOCK)
|
|
fds[fd] = dev_path
|
|
except PermissionError:
|
|
emit({"error": f"Permission denied: {dev_path}"})
|
|
|
|
if not fds:
|
|
emit({"error": "Could not open any keyboard devices"})
|
|
return 1
|
|
|
|
emit({"status": "ready", "devices": list(fds.values())})
|
|
|
|
try:
|
|
while True:
|
|
readable, _, _ = select.select(list(fds.keys()), [], [])
|
|
for fd in readable:
|
|
try:
|
|
data = os.read(fd, EVENT_SIZE * 64)
|
|
for offset in range(0, len(data), EVENT_SIZE):
|
|
chunk = data[offset : offset + EVENT_SIZE]
|
|
if len(chunk) < EVENT_SIZE:
|
|
break
|
|
_, _, ev_type, code, value = struct.unpack(EVENT_FORMAT, chunk)
|
|
# value: 0=release, 1=press, 2=repeat (we ignore repeat)
|
|
if ev_type == EV_KEY and value in (0, 1):
|
|
emit({"keycode": code, "pressed": value == 1})
|
|
except BlockingIOError:
|
|
pass
|
|
except KeyboardInterrupt:
|
|
pass
|
|
finally:
|
|
for fd in fds:
|
|
os.close(fd)
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|