Get a KeyboardEvent.key-style string from an event
  • JavaScript 94.9%
  • TypeScript 5.1%
Find a file
2026-03-18 10:59:04 +01:00
.gitignore Build the cjs file from the es file 2020-04-01 15:42:40 +02:00
.npmignore Add ESM support 2019-11-07 22:24:20 +01:00
index.d.cts Provide separate type declarations for ESM and CJS 2023-05-17 10:16:29 +02:00
index.d.ts Add TS declaration file 2018-09-17 14:47:47 +02:00
index.js Narrow down the amount of situations in which we ignore .key on macOS 2023-06-07 09:40:27 +02:00
LICENSE Update maintainer email 2023-01-24 08:41:31 +01:00
package.json Update repository link 2026-03-18 10:59:04 +01:00
README.md Mention base and shift exports in readme 2019-03-06 09:10:39 +01:00
rollup.config.js Simplify file name of main script 2023-05-17 10:15:57 +02:00

W3C keyname

Tiny library that exports a function keyName that takes a keyboard event and returns a KeyboardEvent.key-style string. Will use the actual key property of the event if available, and fall back to a value synthesized from the keyCode otherwise.

Probably often wrong on non-US keyboards, since the correspondence between a key code and the character it produces when shift is held is predicted based on a hard-coded table. Meant as a fallback for KeyboardEvent.key, not a replacement.

The lookup tables from key codes (event.keyCode) to names are exported as base (when Shift isn't held) and shift (when Shift is held).

License: MIT