New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

key-event-utils

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

key-event-utils

KeyBoard Key Event Utils

latest
npmnpm
Version
1.0.6
Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

Keyboard Event Utils ⌨️

version License typeScript

KeyboardEventUtils is a utility module for handling keyboard events in React applications. It provides helper functions to check for specific key presses, optionally with modifier keys (e.g., Ctrl, Alt, Shift, Meta) and by default strict check for the key.

Features

  • Detects specific key presses such as Enter, Tab, Escape, arrow keys, and more.
  • Supports checking for modifier keys (Ctrl, Alt, Shift, Meta/Cmd).
  • Simplifies keyboard event handling in React components.

Installing

  npm i key-event-utils

Importing the Utility

import {KeyboardEventUtils} from 'key-event-utils';

Usage

Each key has a corresponding function to check if it was pressed. For example:

function handleKeyDown(event: React.KeyboardEvent) {
  if (KeyboardEventUtils.isEnterKey(event)) {
    console.log("Enter key pressed! No modifiers Pressed");
  }
if (KeyboardEventUtils.isEnterKey(event,"*")) {
    console.log("Enter key pressed!"); // Any modifiers is allowed
  }
  if (KeyboardEventUtils.isEscapeKey(event, "ctrl")) {
    console.log("Escape key pressed with Ctrl!");
  }
}

You can specify modifiers as a string; Case doesn’t matter ctrl, Ctrl or CTRL will work. Supported modifiers are:

  • ctrl
  • alt
  • shift
  • meta or cmd, mentioning one modifier itself will work, no need for OS specific.

Some methods can also used for strict check for modifiers

  function handleKeyDown(event: React.KeyboardEvent) {
    if ( ( event.key === "v" || event.key === "v" ) && KeyboardEventUtils.isCtrlKeyPressed(event)) {
      console.log("Ctrl + V");
    }
    if ( ( event.key === "v" || event.key === "v" ) && KeyboardEventUtils.isCtrlKeyPressed(event,"ctrl + shift") ) {
      console.log("Ctrl + V");
    }
  }

Keys Supported

The following keys are supported and its corresponding methods:

  • Enter -isEnterKey
  • Tab - isTabKey
  • Escape - isEscapeKey
  • Backspace - isBackspaceKey
  • Delete - isDeleteKey
  • Arrow keys: ArrowUp, ArrowDown, ArrowLeft, ArrowRight - isUpArrowKey ... got the pattern right?

The following methods are used for strict checks for modifiers:

  • Shift - isShiftKey
  • Ctrl - isCtrlKey
  • Alt - isAltKey
  • Cmd or Meta - isCmdKey or isMetaKey

Maintainer

  • Sasikumar

Keywords

keyboard

FAQs

Package last updated on 24 Feb 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts