*/ private array $held = []; /** @var array */ private array $events = []; /** Hexadecimal characters typed (password screen) */ private string $typed = ''; public function setHeld(string $key, bool $held): void { $was = $this->held[$key] ?? false; if ($held !== $was) { $this->events[] = [$held ? 'down' : 'up', $key]; } $this->held[$key] = $held; } /** A key press that is not held (touch, scripted demo). */ public function press(string $key): void { $this->events[] = ['down', $key]; $this->events[] = ['up', $key]; } public function held(string $key): bool { return $this->held[$key] ?? false; } /** @return array */ public function takeEvents(): array { $events = $this->events; $this->events = []; return $events; } public function type(string $chars): void { $this->typed .= $chars; } public function takeTyped(): string { $typed = $this->typed; $this->typed = ''; return $typed; } /** Forget everything pending (new screen). */ public function flush(): void { $this->events = []; $this->typed = ''; } }