
Product
Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.
keyboard-ts
Advanced tools
A library for listening to keyboard shortcuts and combos, such as Ctrl + Z
, Ctrl + Shift + Z
npm i keyboard-ts
# or
yarn add keyboard-ts
import { Key, Keyboard } from 'keyboard-ts'
const target = document.getElementById('target')
const keyboard = new Keyboard(target)
// listen to Del + Esc
keyboard.on([ Key.Escape, Key.Delete ], () => {
/* do something ... */
})
// listen to Space
keyboard.on([ Key.Space ], event => {
// event is classic HTML event
event.preventDefault()
/* do something ... */
})
// listen to Ctrl+Z
keyboard.on([[ Key.Ctrl, Key.Z ]], () => {
/* do something ... */
})
// listen to Ctrl+Shift+Z
keyboard.on([[ Key.Ctrl, Key.Shift, Key.Z ]], () => {
/* do something ... */
})
// listen to Ctrl+Z or Ctrl+Y
keyboard.on([[ Key.Ctrl, Key.Z ], [ Key.Ctrl, Key.Y ]], () => {
/* do something ... */
})
// listen to Ctrl+Z+X
keyboard.on([[ Key.Ctrl, Key.Z, Key.X ]], () => {
/* do something ... */
})
// remove all listeners
keyboard.clear()
new Keyboard(target: HTMLElement)
Instantiate new keyboard shortcut manager. This manager will listen to key combos pressed on the target
HTML element.
keyboard.on(combo: Key[], (event: KeyboardEvent) => void)
keyboard.on(combos: Key[][], (event: KeyboardEvent) => void)
Start listening to when a combo
(combination of keyboard keys) is pressed at the same time.
The callback receives the keyboard event triggered by the last pressed key of the combo. (e.g. If Ctrl + Z, triggers Ctrl press event and then Z press event, the callback will receive the Z press event.)
Instead of one combo
, and array of combos
can be passed in. In that case the callback is triggered if any of the
combos is pressed.
keyboard.pause()
Temporarily pause listening to any keyboard combos. Can be reversed by calling keyboard.unpause()
.
keyboard.unpause()
Start listening again to keyboard combos again after keyboard.pause()
was called.
keyboard.clear()
Remove all listeners.
window.alert()
inside the callback.import { Key, Keyboard } from 'keyboard-ts'
const target = document.getElementById('target')
const keyboard = new Keyboard(target)
// Do NOT use alert() as a callback!
keyboard.on([ Key.Ctrl, Key.A ], () => {
❌ alert('stuff')
// alert() erases the subsequent 'mouseup' event and this breaks the functionality
// of the Keyboard class, because it has no way of knowing whether a key was released or not.
})
keyboard.on([ Key.Ctrl, Key.A ], () => {})
where callback was getting triggered when any of the keys from the combo was pressedFAQs
Keyboard shortcut listener library in TS
We found that keyboard-ts demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Product
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
Research
A malicious package uses a QR code as steganography in an innovative technique.