Skip to content

Root: ui|v2.5|src|@types: mousetrap‐pause.d.ts

Serechops edited this page Apr 9, 2024 · 2 revisions

mousetrap-pause.d.ts

This TypeScript declaration file extends the functionality of the mousetrap library by adding methods for pausing and unpausing keyboard shortcuts. The MousetrapPause function takes an instance of MousetrapStatic from the mousetrap library and returns an extended instance with additional pause-related methods.

The extended MousetrapStatic interface includes the following methods:

  • pause(): Pauses all keyboard shortcuts.
  • unpause(): Unpauses all keyboard shortcuts.
  • pauseCombo(combo: string): Pauses a specific keyboard shortcut combo.
  • unpauseCombo(combo: string): Unpauses a specific keyboard shortcut combo.

These methods allow developers to dynamically pause and unpause keyboard shortcuts as needed, providing greater control over user interaction in web applications.

Example:

import Mousetrap from "mousetrap";
import MousetrapPause from "mousetrap-pause";

// Create an instance of Mousetrap
const mousetrap = Mousetrap();

// Extend Mousetrap with pause functionality
const extendedMousetrap = MousetrapPause(mousetrap);

// Bind a keyboard shortcut
extendedMousetrap.bind("ctrl+s", () => {
  console.log("Save command triggered");
});

// Pause all keyboard shortcuts
extendedMousetrap.pause();

// Perform some action where keyboard shortcuts should be disabled

// Unpause all keyboard shortcuts
extendedMousetrap.unpause();

Explanation:

In this example, the mousetrap-pause module is used to extend the functionality of the mousetrap library. Keyboard shortcuts can be paused and resumed dynamically to control user interaction during certain application states.

Clone this wiki locally