Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

is-hotkey

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

is-hotkey

Check whether a browser event matches a hotkey.

  • 0.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is is-hotkey?

The is-hotkey npm package is a utility for detecting keyboard shortcuts in JavaScript applications. It allows developers to easily check if a specific key combination has been pressed, making it useful for implementing custom keyboard shortcuts in web applications.

What are is-hotkey's main functionalities?

Basic Hotkey Detection

This feature allows you to detect if a specific key combination, such as 'mod+s' (Ctrl+S on Windows/Linux or Command+S on macOS), has been pressed. The 'isHotkey' function takes a string representing the key combination and an event object, and returns true if the combination matches the event.

const isHotkey = require('is-hotkey');

if (isHotkey('mod+s', event)) {
  console.log('Save command detected');
}

Custom Hotkey Detection

This feature allows you to create a custom hotkey detection function. The 'isHotkey' function can be used to create a reusable function that checks for a specific key combination. This is useful for adding multiple event listeners or for more complex hotkey logic.

const isHotkey = require('is-hotkey');

const customHotkey = isHotkey('ctrl+shift+k');

document.addEventListener('keydown', (event) => {
  if (customHotkey(event)) {
    console.log('Custom hotkey detected');
  }
});

Multiple Hotkey Detection

This feature allows you to detect multiple hotkeys with a single function call. By passing an array of key combinations to the 'isHotkey' function, you can check if any of the specified combinations match the event.

const isHotkey = require('is-hotkey');

const hotkeys = ['mod+s', 'ctrl+shift+k'];

document.addEventListener('keydown', (event) => {
  if (isHotkey(hotkeys, event)) {
    console.log('One of the hotkeys detected');
  }
});

Other packages similar to is-hotkey

Keywords

FAQs

Package last updated on 24 Nov 2020

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc