Typing with a Remote: Vision-Bootstrapped Graph Navigation for On-Screen Keyboards
How we turned TV keyboards into graphs, why a 1950s search algorithm does the typing, and what four TV platforms taught us along the way.
Alexandru Onț

The flakiest step in TV automation is typing
Nearly every end-to-end test we run on Smart TVs has to type something: a search query, an email address, a password. On the web, that's a single sendKeys() call. On a TV there is no keyboard to send keys to, only a remote. Our automation has to press the D-pad over and over to move a highlight across an on-screen keyboard, one key at a time, then press OK.
Every press is a chance to go wrong. If one press is missed, or the robot assumes the highlight is somewhere it isn't, the test types hrllo instead of hello and fails, and the failure looks like a bug in the app rather than in the test.
The problem multiplies across devices. We test on Fire TV, Apple TV, Roku and Samsung Tizen. Each app ships its own keyboard on each platform, with a different layout, a different starting key and a different set of modes for lowercase, uppercase, numbers, symbols and accented letters. Today our automation handles 35 keyboard graphs, one per layout and mode, across those four platforms.

Figure 1. Two of our on-screen keyboards. Left: Samsung Tizen, QWERTY with four staggered rows. Right: an alphabetical layout split into four separate blocks. Same task, completely different maps.
Why the obvious approaches fail
Recorded key sequences. The simplest approach is to record the presses once and replay them: RIGHT, RIGHT, DOWN, OK…. To give a sense of scale: typing qa.test@mail.com on our Tizen keyboard takes 83 presses. A recorded script hard-codes all 83. It breaks the moment the layout changes, the app moves the starting key, or a locale adds a row, and every new string needs a new recording. With 35 keyboards and dozens of test strings, recordings don't scale.
Vision-LLM agents look like a natural fit, but recent work suggests otherwise. TVWorld (Ma et al., 2026) built a benchmark of 500 remote-control navigation tasks on real Smart TV settings menus and found that today's vision-language agents lack topology awareness: they struggle to plan multi-step moves through a UI where you can only shift a highlight up, down, left or right. With up to 50 steps per task, the best general-purpose model tested, Gemini 3 Flash, reached its target 66% of the time. GPT-5 mini managed 60% and Claude Haiku 4.5 25%. Even the authors' own TV-specialised model topped out at 68%.
Those tasks were menu navigation, not typing, but typing is harder in one important way: an email address chains dozens of moves, and a single wrong one corrupts the text. For a test that has to type a password correctly every time, a one-in-three failure rate per navigation task is not an option.
The core problem has a known solution, and we want to credit it clearly. Stb-tester's stbt.Keyboard models an on-screen keyboard as a graph: keys are nodes, remote presses are edges, and all modes (lowercase, uppercase, symbols) live in one graph, so switching modes is just another step on the path. It finds the shortest path to each character, then checks which key is actually focused and retries if a press was missed. It even handles keys whose UP or DOWN target depends on where you came from, by giving those edges a high cost so the planner avoids relying on them.
We took the same graph-and-shortest-path idea and built it into a service that fits our setup. It locates each keyboard on screen with computer vision, generates graphs for keyboards whose rows have different numbers of keys, and drives Fire TV, Apple TV, Roku and Tizen over three different control channels (IR, HDMI-CEC and Roku's ECP) behind a single HTTP API. The rest of this post describes how it works, where it differs from stb-tester, and what the TVs taught us.
The mental model: a keyboard is a map, and the remote gives you four moves
Forget pixels for a moment. To a remote control, an on-screen keyboard is a map: each key is a location, and each D-pad press moves you to a neighbouring one. That makes it a directed graph. Every key is a node, and every press is an edge labelled with its direction: from g, RIGHT leads to h, DOWN leads to b. The edges are directed because the map isn't always symmetric. Going UP and then DOWN doesn't always bring you back where you started, which will matter later.
With that model, typing a character becomes a classic problem: find the shortest path from the currently highlighted key to the target key, follow it, then press OK. Every press costs the same (one button, one animation), so plain breadth-first search is enough. BFS explores keys in rings of increasing distance, so the first time it reaches the target it has found a path with the fewest possible presses.
TVWorld (Ma et al., 2026) arrived at the same formulation for TV menus: UI states as nodes, key presses as directed edges. That's encouraging, because it suggests the model is the natural one for focus-based TV interfaces in general, not a trick that only works for keyboards.

Figure 2. The keyboard as a graph. Starting on q, BFS finds that reaching @ takes 10 presses (DOWN, then nine RIGHTs), followed by OK. Boxes show the key positions our pipeline inferred from a screenshot.
The whole search fits in a dozen lines. This is the function our service calls for every character:
def find_path_to_index(graph, start, target):
q = deque([start])
prev = {start: (None, None)} # node -> (came_from, direction)
while q:
node = q.popleft()
for direction, nxt in graph[node].items():
if nxt is None or nxt in prev:
continue
prev[nxt] = (node, direction)
if nxt == target: # walk back to recover the presses
path, cur = [], nxt
while prev[cur][0] is not None:
cur, d = prev[cur]
path.append(d)
return path[::-1] # e.g. ["down", "right", "right"]
q.append(nxt)
return None
graph is loaded from a JSON file per keyboard. Each key stores its four neighbours, or null where pressing that direction does nothing.
Modes: a map of maps
Real keyboards have more than one face. Pressing ABC swaps the lowercase letters for uppercase ones; 123? brings up digits and symbols. Each mode is effectively a different keyboard on the same screen area, with its own keys and its own neighbours.
We model this in two levels. Each mode has its own navigation graph, built and tested independently. Above them sits a small mode graph: its nodes are modes, and its edges are the toggle keys that switch between them. It's plain configuration, not code:
"transitions": {
"abc": {"ABC": "ABC", "123?": "123"},
"ABC": {"abc": "abc", "123?": "123"},
"123": {"abc": "abc"}
}
To type a character, the service:
Finds a mode that contains it, preferring the current one so it never switches without need.
Runs BFS over the mode graph to get the shortest sequence of toggles, e.g. abc → ABC.
Runs BFS inside the current mode's graph to reach each toggle and press it, then reaches the character itself.
Here is what that looks like for the string Hi@ on our Tizen keyboard:
Step | Presses sent | What happens |
Switch to uppercase | DOWN DOWN OK | q → a → ABC toggle. Focus returns to the first key |
H | DOWN RIGHT×5 OK | Q → A → S → D → F → G → H |
Switch back to lowercase | DOWN LEFT×5 OK | H → B → V → C → X → Z → abc toggle. Focus returns to q |
i | RIGHT×7 OK | q → w → e → r → t → y → u → i |
@ | DOWN RIGHT RIGHT OK | i → k → l → @ |
Three characters took 29 presses, and two of the five OK presses were spent switching modes, not typing.
This two-level design has a cost we should be upfront about. Because step 1 picks the first mode that contains the character, the plan is optimal within each mode but not across them. stb-tester puts every mode into one combined graph, so a single shortest-path search weighs "switch modes here" against "walk further first" automatically. Our split kept each mode's graph simple to generate and debug while we were adding platforms; merging them into one graph is on our list.
Building the graph from pixels
Writing 35 graphs by hand, with four neighbours per key, would mean thousands of edges to type and keep correct. Instead, we generate them from a screenshot plus a small layout file. The work splits cleanly between what vision is good at and what a person knows for certain:
The layout file lists each row's keys in order, e.g. q w e r t y u i o p / a s d f g h j k l @ / … It's a few lines per keyboard, and it's the one part we write by hand.
Computer vision finds where the keyboard is. A YOLO detector, fine-tuned on screenshots of our keyboards, draws a box around the keyboard region in an HDMI capture.
Geometry does the rest. The detected region is split into rows, and each row is split into as many equal-width cells as the layout says it has keys. That handles keyboards like Tizen's, where a 10-key letter row sits above a 7-key bottom row.
Edges then come from how the boxes overlap. LEFT and RIGHT are the neighbours in the same row. For UP and DOWN, we look at the row above or below and keep only the keys whose box spans this key's horizontal centre:
# UP: only keys in the row above whose box spans this key's x-centre
overlapping = [k for k in rows[row - 1] if k["bbox"][0] <= cx <= k["bbox"][2]]
if overlapping:
neighbors["up"] = min(overlapping, key=lambda k: abs(k["center"][0] - cx))["index"]
# no overlap -> no edge: the planner can't send the cursor off the keyboard
The output is one JSON graph per layout and mode. At runtime the service only loads these files, so no model runs while a test is typing.
We didn't start here. Our first attempts tried to find every individual key from pixels alone, and it didn't work: keys on a TV capture are low-contrast and small, and the detector missed most of them. A single uniform grid over the whole keyboard was closer, but broke on the bottom row, where keys have different widths. Telling the geometry how many keys each row has was the step that made it reliable.

Figure 3. How we got here. Finding keys from pixels alone missed most of them (1); grids that ignored the layout drifted off the keys (2, 3); splitting each row by its known key count lined up with the keyboard (4).
One limitation remains, and it's visible in Figure 3: cells are equal width within a row, so on the bottom row the cells don't sit exactly over the wide space bar and the narrow arrow keys. The overlap rule tolerates this in practice, but reading key widths from the screen is on our list.
Talking to four kinds of TV
A plan is only useful if something can press the buttons. Our four platforms don't agree on how to receive them, so the service hides each one behind the same small controller interface (navigate, select, keypress) and picks the right channel per device:
Samsung Tizen receives infrared, exactly like a physical remote.
Fire TV and Apple TV receive HDMI-CEC commands over the same cable that carries the picture.
Roku exposes ECP, an HTTP API on the local network, so a keypress is a web request.
Each press is followed by a short pause (0.3–0.4 s) to let the TV's focus animation finish before the next one arrives.
The service itself is a small FastAPI app. A test calls POST /type with the platform, app and text. The service answers immediately with 202 Accepted and types in the background, so the test isn't blocked for the 30+ seconds a long string can take. Tests poll GET /sessions/{ip} for per-character progress, and can call POST /stop_typing at any point, which also clears the field and returns the cursor to its starting key. Only one typing job runs per device at a time; a second request gets 409 Conflict instead of two jobs fighting over the same remote.

Figure 4. Two phases. Offline, once per keyboard: a capture becomes a navigation graph. Online, on every test: the service plans presses with BFS and sends them over IR, HDMI-CEC or ECP.
What the TVs taught us: focus has memory
Our first version assumed the graph built from geometry was the whole truth: if the boxes say DOWN from h lands on b, then it does. Mostly, that holds. Across our 35 graphs, 98% of edges are reciprocal: press RIGHT then LEFT and you're back where you started. The remaining 2% (90 of 5,026 edges) are one-way. The real surprises, though, came from behaviour no screenshot can show.
The reason is that a TV's focus engine has memory. Where the highlight lands often depends on where it came from, or on what you pressed last. Every platform taught us a version of this, and almost all of it involved the space bar and mode switches:
The space bar is a special case everywhere. It's the widest key, so the key above it depends on where you entered it. We ended up with five different space-bar strategies:
On Roku, we skip navigation entirely and send a space as a literal character over ECP.
On Fire TV, we press UP after typing a space, so the highlight returns to a known key before the next character.
On Tizen, the path that reliably lands on space goes through a neighbouring function key first.
On one of our apps, space only works when approached from the key to its left.
On Apple TV, we navigate to space directly but pin which of its positions to target.
Mode switches move the focus. After pressing a mode toggle, the highlight doesn't always stay on "the same key". On our Tizen keyboard, it jumps back to the first key of the new layout (you can see this in the Hi@ example above). 6 of our 18 app-and-platform configurations needed an explicit map of where the focus lands after each toggle.
Some toggles need two presses. On one Tizen keyboard, the caps toggle has to be pressed twice, or the mode flips straight back.
The lesson: geometry gives you a graph that is almost right, and the last few percent is behaviour you can only learn on the device. We're not the first to hit this. stb-tester's keyboard model gives history-dependent edges a high cost so its planner avoids relying on them. We took a more literal route and encoded each quirk as an explicit path.
Results
Because every keyboard is a graph, we can measure the cost of typing on all of them without touching a TV. For each of our 35 production graphs, we computed the shortest path between every pair of characters in the same mode.
4.7 presses per character on average, before OK. At our 0.4 s pacing, that's about 2.3 seconds per character including the OK press.
qa.test@mail.com on Tizen takes 83 presses, about 33 seconds. A short string with mode switches is worse per character: Hi@ took 29 presses, nearly 10 per character, because two of them needed a mode change.
Layout shape matters more than platform. Most of our keyboards cluster between 3.5 and 5 presses per character. Two Apple TV layouts, laid out as long single rows, average 9 and 11, more than twice as many. On the alphabetical one, moving from a to z takes 25 presses.

Figure 5. Average D-pad presses needed to reach a character, one dot per production keyboard graph. Grid keyboards cluster around the mean of 4.7; single-row layouts cost more than twice as much.
These are model numbers: they're what the graph says typing costs, assuming every press lands. They're also exactly the numbers that justify the work. At 2–4 seconds per character, a hand-written press sequence that's off by one key wastes the whole test run, and a planner that finds the shortest path every time is the cheapest speed-up available.
What we'd do next
Today the service runs open loop: it tracks the highlight in software and trusts that every press arrived. IR and CEC occasionally drop a press, and when that happens, every character after it lands one key off. The fix is to look before moving on: after each character, grab a frame, find the highlighted key, and re-plan from where the focus actually is. stb-tester's keyboard already works this way, with a focus check per character and automatic retries, and it's the bar we want to reach. Finding a highlight is a narrow, well-defined vision problem, a bright key on a dark keyboard, so we expect a small detector to beat a general model here. For comparison, the best model on TVWorld's focus-localisation benchmark is right about 82% of the time.
Merge the modes into one graph. Folding every mode into a single graph, with toggles as ordinary edges, would let one search weigh "switch now" against "switch later" and remove the gap between our plan and the true optimum.
Read more from the screen. Key labels still come from hand-written layout files, and cells are equal width within a row. Reading labels and key widths straight from the capture would make adding a new keyboard nearly free.
Move quirks into data. Our device-specific workarounds still live in code. Expressing them per layout in configuration, as explicit extra edges or post-press focus rules, would make them visible, reviewable and testable.
Takeaways
Use ML only where perception is needed. A detector finds the keyboard; a search algorithm from the 1950s does the typing. The model runs once per keyboard, offline, and never sits in the path of a test.
Model the device as a graph, then expect it to be wrong in places. Geometry got 98% of our edges right. The rest is device behaviour, and it needs a clear, tested home. Ours still lives in if platform == branches, and moving it into per-layout configuration is the next refactor.
Know what already exists, and say so. stb-tester solved the core problem years ago. Starting from its ideas, and being explicit about where we differ, made our design better and this post more honest.
Verify state on hardware. A planner is only as good as its assumption about where the focus is. Any open-loop system eventually drifts; checking the screen after each character is what turns a fast typist into a reliable one.
References
Ma, Z., Lu, Q., Zhong, S., Yu, D., Luo, P., & Ng, M. K. (2026). TVWorld: Foundations for Remote-Control TV Agents. arXiv:2601.13142. https://arxiv.org/abs/2601.13142
Stb-tester. stbt.Keyboard, Python API reference. https://stb-tester.com/manual/python-api#stbt.Keyboard
Stb-tester. Testing on-screen keyboards. https://stb-tester.com/manual/keyboard
Moore, E. F. (1959). The shortest path through a maze. Proceedings of the International Symposium on the Theory of Switching.
Roku. External Control Protocol (ECP). https://developer.roku.com/docs/developer-program/dev-tools/external-control-api.md