MCPcopy
hub / github.com/codeaashu/claude-code / holdKey

Function holdKey

src/utils/computerUse/executor.ts:475–507  ·  view source on GitHub ↗
(keyNames: string[], durationMs: number)

Source from the content-addressed store, hash-verified

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()

Callers

nothing calls this directly

Calls 7

requireComputerUseInputFunction · 0.85
drainRunLoopFunction · 0.85
isBareEscapeFunction · 0.85
notifyExpectedEscapeFunction · 0.85
releasePressedFunction · 0.85
sleepFunction · 0.50
pushMethod · 0.45

Tested by

no test coverage detected