Package detail

@fluentui/keyboard-key

microsoft683kMIT0.4.23

A simple utility for determining the KeyboardEvent.key property from a keyboard event.

readme

@fluentui/keyboard-key

A simple utility for determining the KeyboardEvent.key property from a keyboard event.

Install

yarn add keyboard-key

# or

npm install keyboard-key

Usage

getKey()

Get the key property value from an event.

document.addEventListener('keydown', event => {
  const key = keyboardKey.getKey(event);

  switch (key) {
    case 'Escape':
      // handle escape key
      break;
    default:
      break;
  }
});

See MDN or the source for a full list of key values.

getCode()

You can also get the normalized keyCode from an event. @fluentui/keyboard-key includes a hash of key names to keyCodes for easy comparisons:

document.addEventListener('keydown', event => {
  const code = getCode(event);

  switch (code) {
    case keyboardKey.Escape: // 27
      // handle escape key
      break;
    default:
      break;
  }
});

Why?

Most previous key identifying KeyboardEvent properties have been pressed have been deprecated in favor of Keyboard.key.

:-1: KeyboardEvent.char :-1: KeyboardEvent.charCode :-1: KeyboardEvent.keyCode :-1: KeyboardEvent.keyIdentifier :-1: KeyboardEvent.keyLocation :-1: KeyboardEvent.which

:+1: KeyboardEvent.key

Unfortunately, KeyboardEvent.key does not yet have full browser support. Leaving the browsers without a reliable property for identifying keyboard event keys.

Locale Caveat

This utility interprets use of the shift key when inferring event key values. Example, an event describing <kbd>shift</kbd>+<kbd>/</kbd> would result in a key value of <kbd>?</kbd>. This logic assumes an en-US locale keyboard layout. This will not work if you are using a different locale such as a German layout where <kbd>/</kbd> is <kbd>shift</kbd>+<kbd>7</kbd>.

changelog

Change Log - @fluentui/keyboard-key

This log was last generated on Fri, 05 May 2023 18:14:05 GMT and should not be manually modified.

0.4.9

Fri, 05 May 2023 18:14:05 GMT Compare changes

Patches

  • fix: explicitly ship dist/ folder. (PR #27769 by tristan.watanabe@gmail.com)

0.4.8

Tue, 02 May 2023 00:58:15 GMT Compare changes

Patches

  • fix: esm, cjs, and amd folders should all be published correctly. (PR #27736 by tristan.watanabe@gmail.com)

0.4.0

Thu, 03 Mar 2022 07:24:26 GMT Compare changes

Minor changes

  • Adding explicit export maps on all consumer packages for FUIR 8 and 9. (PR #21508 by dzearing@microsoft.com)

0.3.4

Tue, 03 Aug 2021 07:39:30 GMT Compare changes

Patches

  • Bump @fluentui/eslint-plugin to v1.3.3 (PR #19169 by behowell@microsoft.com)

0.3.3

Fri, 09 Jul 2021 07:39:31 GMT Compare changes

Patches

  • Bump @fluentui/eslint-plugin to v1.3.2 (PR #18808 by martinhochel@microsoft.com)

0.3.2

Mon, 07 Jun 2021 07:38:15 GMT Compare changes

Patches

  • Bump @fluentui/eslint-plugin to v1.3.1 (PR #18437 by martinhochel@microsoft.com)

0.3.1

Thu, 20 May 2021 07:41:54 GMT Compare changes

Patches

  • Bump @fluentui/eslint-plugin to v1.3.0 (PR #18024 by elcraig@microsoft.com)

0.3.0

Fri, 30 Apr 2021 07:42:23 GMT Compare changes

Minor changes

  • Upgrade to typescript 4.1.5 (PR #17932 by joschect@microsoft.com)

Patches

  • Bump @fluentui/eslint-plugin to v1.2.0 (PR #17932 by joschect@microsoft.com)
  • Bump @fluentui/scripts to v1.0.0 (PR #17932 by joschect@microsoft.com)

0.2.17

Fri, 23 Apr 2021 07:37:10 GMT Compare changes

Patches

  • Bump @fluentui/eslint-plugin to v1.1.1 (PR #17894 by olfedias@microsoft.com)

0.2.16

Wed, 31 Mar 2021 00:53:43 GMT Compare changes

Patches

  • Bump @fluentui/eslint-plugin to v1.1.0 (PR #17568 by elcraig@microsoft.com)

0.2.15

Tue, 30 Mar 2021 07:34:45 GMT Compare changes

Patches

  • chore: restore "sideEffects" to enable treeshaking (PR #17584 by olfedias@microsoft.com)

0.2.14

Fri, 26 Feb 2021 01:16:27 GMT Compare changes

Patches

  • Bump @fluentui/eslint-plugin to v1.0.1 (PR #17169 by elcraig@microsoft.com)

0.2.13

Thu, 18 Feb 2021 12:27:34 GMT Compare changes

Changes

  • Bump @fluentui/eslint-plugin to v1.0.0-beta.2 (PR #16975 by elcraig@microsoft.com)
  • Bump @fluentui/scripts to v1.0.0 (PR #16975 by elcraig@microsoft.com)

0.2.13

Mon, 01 Feb 2021 12:23:48 GMT Compare changes

Patches

  • add prerelease in disallowed change type for version packages and fix current versioning. (PR #16696 by xgao@microsoft.com)

0.2.4

Thu, 02 Jul 2020 12:42:11 GMT Compare changes

Patches

  • Resolve side effects in keyboard-key/codes.ts (PR #13729 by connorjsmith101@gmail.com)

0.2.0

Fri, 08 May 2020 12:35:40 GMT Compare changes

Minor changes

  • keyboard-key: Reducing bundle size. (PR #12339 by humbertomakotomorimoto@gmail.com)

0.1.7

Thu, 07 May 2020 01:06:55 GMT Compare changes

Patches

  • Addressing commonjs imports. (PR #13031 by dzearing@microsoft.com)

0.1.4

Wed, 25 Mar 2020 12:30:04 GMT

Patches

  • Changing references of Fabric to Fluent (mgodbolt@microsoft.com)

    0.1.3

    Mon, 23 Mar 2020 12:28:29 GMT

Patches

  • Replace OfficeDev/office-ui-fabric-react with microsoft/fluentui (elcraig@microsoft.com)

    0.1.1

    Tue, 17 Mar 2020 12:28:58 GMT

Patches

  • Creating a fork of the keyboard-key library to convert to typescript, produce es6, add typings, and reduce bundle. Hooking up to bundle validation as well. (dzearing@microsoft.com)