(keyNames: string[], durationMs: number)
| 473 | }, |
| 474 | |
| 475 | async holdKey(keyNames: string[], durationMs: number): Promise<void> { |
| 476 | const input = requireComputerUseInput() |
| 477 | // Press/release each wrapped in drainRunLoop; the sleep sits outside so |
| 478 | // durationMs isn't bounded by drainRunLoop's 30s timeout. `pressed` |
| 479 | // tracks which presses landed so a mid-press throw still releases |
| 480 | // everything that was actually pressed. |
| 481 | // |
| 482 | // `orphaned` guards against a timeout-orphan race: if the press-phase |
| 483 | // drainRunLoop times out while the esc-hotkey pump-retain keeps the |
| 484 | // pump running, the orphaned lambda would continue pushing to `pressed` |
| 485 | // after finally's releasePressed snapshotted the length — leaving keys |
| 486 | // stuck. The flag stops the lambda at the next iteration. |
| 487 | const pressed: string[] = [] |
| 488 | let orphaned = false |
| 489 | try { |
| 490 | await drainRunLoop(async () => { |
| 491 | for (const k of keyNames) { |
| 492 | if (orphaned) return |
| 493 | // Bare Escape: notify the CGEventTap so it doesn't fire the |
| 494 | // abort callback for a model-synthesized press. Same as key(). |
| 495 | if (isBareEscape([k])) { |
| 496 | notifyExpectedEscape() |
| 497 | } |
| 498 | await input.key(k, 'press') |
| 499 | pressed.push(k) |
| 500 | } |
| 501 | }) |
| 502 | await sleep(durationMs) |
| 503 | } finally { |
| 504 | orphaned = true |
| 505 | await drainRunLoop(() => releasePressed(input, pressed)) |
| 506 | } |
| 507 | }, |
| 508 | |
| 509 | async type(text: string, opts: { viaClipboard: boolean }): Promise<void> { |
| 510 | const input = requireComputerUseInput() |
nothing calls this directly
no test coverage detected