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

mousetrap

Package Overview
Dependencies
Maintainers
2
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mousetrap

Simple library for handling keyboard shortcuts

  • 1.6.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
506K
decreased by-10.64%
Maintainers
2
Weekly downloads
 
Created

What is mousetrap?

Mousetrap is a simple library for handling keyboard shortcuts in Javascript. It allows you to bind key combinations to specific functions, making it easier to create keyboard-driven interfaces.

What are mousetrap's main functionalities?

Binding a single key

This feature allows you to bind a single key to a function. In this example, pressing the 'A' key will trigger an alert.

Mousetrap.bind('a', function() { alert('You pressed A!'); });

Binding a combination of keys

This feature allows you to bind a combination of keys to a function. In this example, pressing 'Ctrl+S' will trigger an alert and prevent the default browser action.

Mousetrap.bind('ctrl+s', function(e) { e.preventDefault(); alert('You pressed Ctrl+S!'); });

Binding sequences of keys

This feature allows you to bind sequences of keys to a function. In this example, pressing 'G' followed by 'I' will trigger an alert.

Mousetrap.bind('g i', function() { alert('You pressed G then I!'); });

Binding keys in a specific context

This feature allows you to bind keys in a specific context, such as 'keydown', 'keyup', or 'keypress'. In this example, pressing 'Command/Control+Enter' will trigger an alert on the 'keydown' event.

Mousetrap.bind('mod+enter', function() { alert('You pressed Command/Control+Enter!'); }, 'keydown');

Unbinding keys

This feature allows you to unbind a previously bound key. In this example, the 'A' key will no longer trigger any function.

Mousetrap.unbind('a');

Other packages similar to mousetrap

Keywords

FAQs

Package last updated on 23 Jan 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