types-keyboardevent provides TypeScript types for KeyboardEvent,
generated directly from W3C UI Events KeyboardEvent specifications.
npm install types-keyboardeventKeyboardEventCoderepresents a union of knownevent.codevalues.KeyboardEventKeyrepresents a union of knownevent.keyvalues.- Includes sub-types such as
KeyboardEventCode.NumpadandKeyboardEventKey.Navigation. - Source is generated directly from:
This package is type-only at runtime. Its JavaScript entrypoints intentionally export no values.
import type { KeyboardEventCode, KeyboardEventKey } from "types-keyboardevent";
const isMovementCode = (code: KeyboardEventCode.Arrowpad) => code === "ArrowLeft" || code === "ArrowRight";
const isConfirmKey = (key: KeyboardEventKey) => key === "Enter" || key === " ";You can also import the type families directly from their subpaths:
import type { KeyboardEventCode } from "types-keyboardevent/KeyboardEventCode";
import type { KeyboardEventKey } from "types-keyboardevent/KeyboardEventKey";Includes values such as "KeyA", "ArrowRight", "NumpadEnter", and media-related codes.
Useful namespaces include:
KeyboardEventCode.ModifierKeyboardEventCode.ArrowpadKeyboardEventCode.NumpadKeyboardEventCode.FunctionKeyboardEventCode.Media
Includes values such as "Enter", "ArrowRight", "AudioVolumeUp", and "MediaPlayPause".
Useful namespaces include:
KeyboardEventKey.ModifierKeyboardEventKey.NavigationKeyboardEventKey.EditingKeyboardEventKey.MultimediaKeyboardEventKey.AudioKeyboardEventKey.Browser