Implementation:Microsoft Playwright UsKeyboardLayout
Overview
UsKeyboardLayout defines the complete US keyboard layout mapping, providing key definitions with key codes, shifted characters, text values, and location information for keyboard input simulation.
Description
This module exports the USKeyboardLayout constant, a comprehensive mapping from key names to KeyDefinition objects. Each definition includes:
key-- the key value stringkeyCode-- the numeric key codeshiftKey-- the character produced when Shift is heldshiftKeyCode-- optional alternate key code with Shifttext-- the text character generatedlocation-- key location (for numpad, left/right modifier keys)
The layout covers function keys, number row, letter keys, punctuation, numpad, modifier keys, and special keys.
Usage
Used by the keyboard input system across all browser implementations to translate key names into key codes and character values.
Code Reference
Source Location
packages/playwright-core/src/server/usKeyboardLayout.ts (155 lines)
Type and Export Signatures
export type KeyDefinition = {
key: string;
keyCode: number;
keyCodeWithoutLocation?: number;
shiftKey?: string;
shiftKeyCode?: number;
text?: string;
location?: number;
};
export type KeyboardLayout = { [s: string]: KeyDefinition };
export const keypadLocation = 3;
export const USKeyboardLayout: KeyboardLayout;
Import
import { USKeyboardLayout, keypadLocation } from './server/usKeyboardLayout';
import type { KeyDefinition, KeyboardLayout } from './server/usKeyboardLayout';
I/O Contract
Structure
- Keys: standard key code names (e.g.,
'KeyA','Digit1','Enter','NumpadMultiply') - Values:
KeyDefinitionobjects with key metadata
Example Entry
'KeyA': { keyCode: 65, key: 'a', shiftKey: 'A' }
'Digit1': { keyCode: 49, shiftKey: '!', key: '1' }
Related Pages
- Microsoft_Playwright_FfInput -- Firefox keyboard input using this layout
- Microsoft_Playwright_WkInput -- WebKit keyboard input using this layout
- Microsoft_Playwright_MacEditingCommands -- macOS editing command mapping