/** * Keyboard event construction utilities. */ import { type KeyDefinition } from './keys.js'; /** * Platform type for smart modifier resolution. */ export type Platform = 'mac' | 'windows' | 'linux'; /** * Detect current platform from navigator or environment. */ export declare function detectPlatform(): Platform; /** * Smart modifier that resolves differently per platform. * ControlOrMeta/CmdOrCtrl -> Meta on Mac, Control elsewhere. */ export type SmartModifier = Modifier | 'ControlOrMeta' | 'CmdOrCtrl'; /** * Resolve a smart modifier to an actual modifier based on platform. */ export declare function resolveSmartModifier(modifier: SmartModifier, platform?: Platform): Modifier; /** * Parse key combination with smart modifier support. * Examples: "ControlOrMeta+A", "CmdOrCtrl+C" */ export declare function parseKeyCombinationSmart(combo: string, platform?: Platform): { modifiers: number; key: KeyDefinition | null; }; export interface KeyboardEventOptions { modifiers?: number; } /** * Modifier key type */ export type Modifier = 'Alt' | 'Control' | 'Meta' | 'Shift'; /** * Options for type operation */ export interface TypeOptions { delay?: number; } /** * Keyboard event init data returned by state methods */ export interface KeyboardEventData { key: string; code: string; keyCode: number; location: number; ctrlKey: boolean; altKey: boolean; shiftKey: boolean; metaKey: boolean; repeat: boolean; } /** * Stateful keyboard that tracks pressed keys and modifiers. * Ports Playwright's keyboard state management pattern. */ export declare class KeyboardState { private pressedModifiers; private pressedKeys; private platform; constructor(platform?: Platform); /** * Get the platform this keyboard is configured for. */ getPlatform(): Platform; /** * Press a key down. Returns the keyboard event data. * Tracks the key as pressed to prevent auto-repeat issues. */ down(key: string): KeyboardEventData; /** * Release a key. Returns the keyboard event data. * Removes key from pressed set. */ up(key: string): KeyboardEventData; /** * Press and release a key. Returns both events. * Handles key combinations like "Control+A". */ press(key: string): { down: KeyboardEventData; up: KeyboardEventData; }; /** * Press a key combination with smart modifier support. * Resolves ControlOrMeta/CmdOrCtrl based on platform. * Examples: "ControlOrMeta+A", "CmdOrCtrl+C" */ pressSmart(combo: string): { down: KeyboardEventData; up: KeyboardEventData; }; /** * Press a key with shift applied if needed. * Used when typing characters that require shift. */ downWithShift(key: string): KeyboardEventData; /** * Check if a key is currently pressed. */ isPressed(key: string): boolean; /** * Check if a modifier is currently active. */ isModifierPressed(modifier: Modifier): boolean; /** * Get the current modifier mask (bitfield). * Alt: 1, Control: 2, Meta: 4, Shift: 8 */ getModifierMask(): number; /** * Ensure specific modifiers are pressed, pressing/releasing as needed. * Returns the modifiers that were actually changed. */ ensureModifiers(required: Modifier[]): { pressed: Modifier[]; released: Modifier[]; }; /** * Get the set of currently pressed modifiers. */ getModifiers(): Set; /** * Get the set of currently pressed keys (by code). */ getPressedKeys(): Set; /** * Reset all state (release all keys and modifiers). */ reset(): void; /** * Get key definition for a key string. * Handles shifted keys based on current modifier state. */ private getKeyDefinition; /** * Create keyboard event data from key definition. */ private createEventData; /** * Split a key combination string like "Control+Shift+A" into parts. */ private splitKeyCombination; } /** * Create a keyboard event. */ export declare function createKeyboardEvent(type: string, keyDef: KeyDefinition, options?: KeyboardEventOptions): KeyboardEvent; /** * Dispatch a key press (keydown, keypress if printable, keyup). */ export declare function dispatchKeyPress(element: Element, key: string, options?: KeyboardEventOptions): boolean; /** * Dispatch a key combination like "Control+A". */ export declare function dispatchKeyCombination(element: Element, combo: string): boolean; /** * Type text into an element character by character. */ export declare function typeText(element: Element, text: string, options?: { delay?: number; }): void; /** * Insert text at the cursor position in an input or contenteditable. */ export declare function insertTextAtCursor(element: Element, text: string): void; /** * Clear the text content of an input element. */ export declare function clearElement(element: Element): void; /** * Fill an element with text (clear + type). */ export declare function fillElement(element: Element, text: string): void; /** * Select all text in an element. */ export declare function selectAll(element: Element): void; /** * Focus an element. */ export declare function focusElement(element: Element): boolean; /** * Blur an element. */ export declare function blurElement(element: Element): boolean; //# sourceMappingURL=keyboard.d.ts.map