keycode-js is a JavaScript package providing a comprehensive set of constants for keyboard events, specifically mapping to KeyboardEvent.keyCode, KeyboardEvent.code, and KeyboardEvent.key properties. The current stable version is 3.1.0. The package maintains a steady release cadence, incorporating new key event codes and values while addressing compatibility and consistency across browser environments. A key differentiator is its provision of constants for all three KeyboardEvent properties, allowing developers to choose the most appropriate and future-proof method for handling keyboard input. It also ships with TypeScript types, enhancing developer experience in TypeScript projects, and offers direct support for Deno environments.
npm install keycode-jsVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to import and use key code, key value, and key event constants from `keycode-js` within a browser's keyup event listener, showing both modern and deprecated approaches.
Review `KeyboardEvent.keyCode` usage. It's highly recommended to migrate to `KeyboardEvent.code` or `KeyboardEvent.key` with their corresponding `CODE_` or `VALUE_` constants for better cross-browser compatibility. If `keyCode` must be used, verify the new constant values against your expected behavior.
Update your import statements. Change `import KeyCode from 'keycode-js';` to `import * as KeyCode from 'keycode-js';` to import the module namespace, or use named imports like `import { KEY_RETURN } from 'keycode-js';` for individual constants.Prioritize the use of `e.code` with `KeyCode.CODE_EXAMPLE` constants or `e.key` with `KeyCode.VALUE_EXAMPLE` constants for handling keyboard events. These offer more reliable and future-proof identification of keys.
Change the import statement to `import * as KeyCode from 'keycode-js';` or `import { KEY_RETURN } from 'keycode-js';`.Ensure the `keycode-js` script tag (`<script src="https://unpkg.com/keycode-js@latest/dist/keycode.min.js"></script>`) is loaded before your script attempts to use `KeyCode`. In modules, ensure it's properly imported.
No dependency data recorded yet.