npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@a11y-oracle/keyboard-engine

v1.3.2

Published

Native CDP keyboard dispatch with modifier key support and focused element introspection

Downloads

2,730

Readme

@a11y-oracle/keyboard-engine

CDP-based keyboard dispatch engine for accessibility testing. Sends native hardware-level keystrokes via Input.dispatchKeyEvent and reads focused element information via Runtime.evaluate.

This is a low-level building block used internally by @a11y-oracle/core-engine. Most users should use the Playwright or Cypress plugin instead.

Installation

npm install @a11y-oracle/keyboard-engine

Usage

import { KeyboardEngine } from '@a11y-oracle/keyboard-engine';

const keyboard = new KeyboardEngine(cdpSession);

// Press a key
await keyboard.press('Tab');

// Press with modifiers
await keyboard.press('Tab', { shift: true });   // Shift+Tab (backward)
await keyboard.press('a', { ctrl: true });       // Ctrl+A (select all)

// Get info about the currently focused element
const el = await keyboard.getFocusedElement();
if (el) {
  console.log(el.tag);      // "BUTTON"
  console.log(el.id);       // "submit-btn"
  console.log(el.role);     // "button"
  console.log(el.tabIndex); // 0
  console.log(el.rect);     // { x: 100, y: 200, width: 120, height: 40 }
}

API Reference

KeyboardEngine

constructor(cdp: CDPSessionLike)

Create a new keyboard engine.

  • cdp — Any object with a send(method, params?) method compatible with CDP.

press(key: string, modifiers?: ModifierKeys): Promise<void>

Dispatch a native key press via CDP Input.dispatchKeyEvent. Sends a keyDown event followed by a keyUp event, matching the behavior of a physical key press.

  • key — Key name from KEY_DEFINITIONS (see table below).
  • modifiers — Optional modifier keys to hold during the press.

Modifier keys map to the CDP bitmask: Alt = 1, Ctrl = 2, Meta = 4, Shift = 8.

Throws if the key name is not in KEY_DEFINITIONS.

getFocusedElement(): Promise<FocusedElementInfo | null>

Get information about the currently focused DOM element via Runtime.evaluate.

Returns null if no interactive element has focus (e.g., document.body or document.documentElement is focused).

Supported Keys

| Key Name | Description | |----------|-------------| | Tab | Tab navigation | | Enter | Activate / submit | | Space or ' ' | Activate / toggle | | Escape | Cancel / close | | ArrowUp | Navigate up | | ArrowDown | Navigate down | | ArrowLeft | Navigate left | | ArrowRight | Navigate right | | Home | Jump to start | | End | Jump to end | | Backspace | Delete backward | | Delete | Delete forward |

Types

KeyDefinition

CDP keyboard event parameters for a single key:

interface KeyDefinition {
  key: string;     // CDP key property (e.g. "Tab")
  code: string;    // CDP code property (e.g. "Tab")
  keyCode: number; // Windows virtual key code (e.g. 9)
}

ModifierKeys

Modifier keys for key press combinations:

interface ModifierKeys {
  shift?: boolean;
  ctrl?: boolean;
  alt?: boolean;
  meta?: boolean;
}

FocusedElementInfo

Information about the currently focused DOM element:

interface FocusedElementInfo {
  tag: string;        // "BUTTON"
  id: string;         // "submit-btn"
  className: string;  // "btn primary"
  textContent: string; // "Submit"
  role: string;       // "button" (from role attribute)
  ariaLabel: string;  // "Submit form" (from aria-label)
  tabIndex: number;   // 0
  rect: { x: number; y: number; width: number; height: number };
}

Exports

export { KeyboardEngine } from '@a11y-oracle/keyboard-engine';
export { KEY_DEFINITIONS } from '@a11y-oracle/keyboard-engine';
export type {
  KeyDefinition,
  ModifierKeys,
  FocusedElementInfo,
} from '@a11y-oracle/keyboard-engine';

How It Works

The engine uses two CDP domains:

  1. Input.dispatchKeyEvent — Sends real hardware-level keystroke events (keyDown + keyUp) directly to the browser. This bypasses synthetic JavaScript event dispatch (element.dispatchEvent()), so the browser handles focus management natively — just as if a user physically pressed the key.

  2. Runtime.evaluate — Executes a JavaScript expression in the page context to read document.activeElement properties (tag, id, class, role, aria-label, tabIndex, bounding rect).