Chat: Ctrl+1-9 puts the keyboard in the opened chat's composer
A chat opened from the keyboard asks its composer for focus; the composer takes it after the frame it is built in (new detail pane or phone page), or at once when that chat is already open. Taps and other opens cancel the request, so they keep focus where it was. The capture kit's press step accepts modifier chords such as Control+2.
This commit is contained in:
@@ -45,7 +45,7 @@ In JSON, a step can also set `wait` (ms), `timeout`, `name`, `ms` and `frames`.
|
||||
| `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) |
|
||||
| `press=Enter` | press a key: Enter, Escape, Tab, Backspace, ArrowUp or ArrowDown |
|
||||
| `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) |
|
||||
| `hover=<target>` | move the mouse onto the target without pressing (hover states) |
|
||||
| `drag=<target>>dx,dy` | press on the target, move by dx,dy in `steps` (12) moves `gap` (16) ms apart, release (JSON `dx`, `dy`, `steps`, `gap`; `hold: true` keeps the button down to capture mid-drag) |
|
||||
|
||||
@@ -127,11 +127,26 @@ export function flutterPage(browser, log) {
|
||||
if (!focused) throw new Error('No text field to type into; click the field first');
|
||||
await send('Input.insertText', { text });
|
||||
},
|
||||
async press(key) {
|
||||
/** Presses [chord]: a key, optionally after `Control+`, `Shift+`, `Alt+` or `Meta+` (e.g. `Control+2`). */
|
||||
async press(chord) {
|
||||
const parts = String(chord).split('+');
|
||||
const key = parts.pop();
|
||||
const bits = { Alt: 1, Control: 2, Meta: 4, Shift: 8 };
|
||||
const modifiers = parts.reduce((m, p) => m | (bits[p] ?? 0), 0);
|
||||
const codes = { Enter: 13, Escape: 27, Tab: 9, Backspace: 8, ArrowDown: 40, ArrowUp: 38 };
|
||||
const base = { key, code: key, windowsVirtualKeyCode: codes[key] ?? 0, text: key === 'Enter' ? '\r' : undefined };
|
||||
const digit = /^\d$/.test(key);
|
||||
const code = digit ? `Digit${key}` : /^[a-z]$/i.test(key) ? `Key${key.toUpperCase()}` : key;
|
||||
const vk = codes[key] ?? (key.length === 1 ? key.toUpperCase().charCodeAt(0) : 0);
|
||||
const text = key === 'Enter' ? '\r' : key.length === 1 && !modifiers ? key : undefined;
|
||||
const base = { key, code, windowsVirtualKeyCode: vk, modifiers, text };
|
||||
for (const p of parts) {
|
||||
await send('Input.dispatchKeyEvent', { type: 'keyDown', key: p, code: `${p}Left`, modifiers });
|
||||
}
|
||||
await send('Input.dispatchKeyEvent', { type: 'keyDown', ...base });
|
||||
await send('Input.dispatchKeyEvent', { type: 'keyUp', ...base, text: undefined });
|
||||
for (const p of parts.reverse()) {
|
||||
await send('Input.dispatchKeyEvent', { type: 'keyUp', key: p, code: `${p}Left`, modifiers: 0 });
|
||||
}
|
||||
},
|
||||
/** Wheel ticks at [target] (default the centre): [repeat] events of dx/dy each, [gap] ms apart. */
|
||||
async scroll(dy, target, { dx = 0, repeat = 1, gap = 16 } = {}) {
|
||||
|
||||
Reference in New Issue
Block a user