Terminal: text input for IMEs, Capture browser keys, touch key row

- Desktop and web terminals use the text-input path too, so IMEs, dead
  keys, the emoji picker and dictation work; the key handler still
  encodes special keys and chords first (handled keys are never typed
  again), composing text is drawn at the cursor and sent on commit, the
  platform editable sits at the cursor, and a closed input reopens on
  the next key. The editable terminal is a semantics text field so web
  typing also works with semantics on.
- Web: "Capture browser keys" (terminal menu and right-click menu) goes
  full screen and calls navigator.keyboard.lock(); hold Esc to leave.
  No-op where unsupported; cheatsheet and menu note give alternatives.
- Touch: scrollable key row with sticky Ctrl/Alt (tap once, double-tap
  lock), Esc, Tab, arrows, Home/End, PgUp/PgDn and symbols through the
  hardware encoder; soft keyboard types per key (delete detection,
  Return as Enter); the line field moves behind the row's Line button.
- Capture kit: compose=, --semantics false, --user-agent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-26 02:43:57 +00:00
parent e526150b1e
commit c5af000453
36 changed files with 1730 additions and 173 deletions
+11 -1
View File
@@ -40,6 +40,15 @@ voice list can then be captured.
Without `theme`, the app follows the browser's colour
scheme. `--theme` also sets that colour scheme through Chrome emulation.
`--semantics false` leaves Flutter's semantics tree off, as for a user without
assistive technology: only point targets (`x,y`) work, and the web's text input
is Flutter's own hidden field, which reports IME composition (with semantics on,
a text field's input is its semantics element, which does not).
`--user-agent '<ua>'` overrides the browser's user agent before loading, so an
Android phone's (with `--touch true`) makes Flutter's `defaultTargetPlatform`
Android, for touch-only UI such as the terminal's key row.
## Steps
You can pass steps on the command line as `verb=value`. With `--script`, they
@@ -52,7 +61,8 @@ In JSON, a step can also set `wait` (ms), `timeout`, `name`, `ms` and `frames`.
| `shot=name` | take a screenshot |
| `click=<target>` | click the centre of the target, then wait `--wait` ms (default 1000) |
| `waitfor=<target>` | wait up to 10 s for the target to appear |
| `type=text` | type into the focused field (or the first visible one) |
| `type=text` | type into the focused field (or the first visible one) through CDP `Input.insertText`, which commits text as an IME, the emoji picker or dictation does |
| `compose=text` | set IME composing text (CDP `Input.imeSetComposition`) in the focused field, as a CJK IME or a dead key does; a following `type=` commits it |
| `press=Enter` | press a key: Enter, Escape, Tab, Backspace, ArrowUp, ArrowDown, a letter or a digit, optionally after `Control+`, `Shift+`, `Alt+` or `Meta+` (`press=Control+2`) |
| `scroll=600` | scroll with the mouse wheel at the centre (JSON `at` sets a target, `dx` a horizontal delta, `repeat` and `gap` a run of ticks) |
| `rightclick=<target>` | click the secondary mouse button on the target (context menus), then wait |
+4 -1
View File
@@ -21,6 +21,8 @@ options: --script <steps.json> --size WxH (880x1000)
--film-ms <ms, 900> --cdp http://127.0.0.1:<port> --probe true|false
--params <query, e.g. chats=2&rich=1, added to every open>
--touch true (emulate a touch screen: mobile metrics, touch input)
--semantics false (leave Flutter semantics off; point targets only)
--user-agent <ua> (e.g. an Android phone's, for defaultTargetPlatform)
steps: open=<route>[@WxH] wait=<ms> shot=<name> click=<target> waitfor=<target>
type=<text> press=<Enter|Escape|Tab|...> scroll=<dy> size=WxH
files=<path>[,<path>] (answers the next file chooser)
@@ -90,7 +92,7 @@ let exitCode = 0;
try {
const base = opts.build ? (server = await serveBuild(opts.build)).origin : opts.url;
browser = await openBrowser({ cdp: opts.cdp });
page = flutterPage(browser, log, { touch: opts.touch === 'true' });
page = flutterPage(browser, log, { touch: opts.touch === 'true', semantics: opts.semantics !== 'false', userAgent: opts['user-agent'] });
for (const step of steps) {
const [verb] = Object.keys(step);
const value = step[verb];
@@ -123,6 +125,7 @@ try {
case 'waitfor': await page.waitFor(value, step.timeout ?? 10000); break;
case 'files': await page.armFiles(String(value).split(',').map((p) => resolve(p))); break;
case 'type': await page.type(String(value)); await delay(step.wait ?? settle); break;
case 'compose': await page.compose(String(value)); await delay(step.wait ?? settle); break;
case 'press': await page.press(String(value)); await delay(step.wait ?? settle); break;
case 'scroll': {
const at = await page.scroll(Number(value), step.at, { dx: Number(step.dx ?? 0), repeat: Number(step.repeat ?? 1), gap: Number(step.gap ?? 16) });
+14 -1
View File
@@ -46,7 +46,7 @@ const LABELS = `(() => [...document.querySelectorAll('flt-semantics, [aria-label
rect: [r.left, r.top, r.width, r.height].map(Math.round) }; })
.filter((n) => (n.label || n.key) && n.rect[2] > 0 && n.rect[3] > 0))()`;
export function flutterPage(browser, log, { touch = false } = {}) {
export function flutterPage(browser, log, { touch = false, semantics = true, userAgent } = {}) {
const { send } = browser;
let viewport = { width: 880, height: 1000 };
const errors = [];
@@ -107,8 +107,17 @@ export function flutterPage(browser, log, { touch = false } = {}) {
await send('Page.bringToFront');
await resize(width, height);
await send('Emulation.setEmulatedMedia', { features: [{ name: 'prefers-color-scheme', value: theme ?? '' }] });
// A phone's user agent makes Flutter's defaultTargetPlatform Android.
if (userAgent) await send('Emulation.setUserAgentOverride', { userAgent, platform: /Android/.test(userAgent) ? 'Linux armv8l' : undefined });
await send('Page.navigate', { url });
await until(() => evaluate("Boolean(document.querySelector('flt-semantics-placeholder'))"), 'Flutter to start', 30000);
if (!semantics) {
// As a user without assistive technology sees it: no semantics tree,
// so only point targets work (the web's text input then is Flutter's
// own hidden field, with IME composition events).
await delay(1500);
return;
}
await evaluate("document.querySelector('flt-semantics-placeholder')?.click()");
await until(() => evaluate("document.querySelectorAll('flt-semantics').length > 0"), 'the semantics tree', 15000);
// Touch starts once semantics is on: the placeholder's click does not
@@ -150,6 +159,10 @@ export function flutterPage(browser, log, { touch = false } = {}) {
if (!focused) throw new Error('No text field to type into; click the field first');
await send('Input.insertText', { text });
},
/** Sets IME composing (marked) text in the focused field, as a CJK IME or a dead key does; a following `type` commits. */
async compose(text) {
await send('Input.imeSetComposition', { text, selectionStart: text.length, selectionEnd: text.length });
},
/** Presses [chord]: a key, optionally after `Control+`, `Shift+`, `Alt+` or `Meta+` (e.g. `Control+2`). */
async press(chord) {
const parts = String(chord).split('+');