
Research
Security News
Malicious npm Packages Use Telegram to Exfiltrate BullX Credentials
Socket uncovers an npm Trojan stealing crypto wallets and BullX credentials via obfuscated code and Telegram exfiltration.
use-keyboard-shortcuts
Advanced tools
An intuitive React hook to enable keyboard shortcuts.
useKeyboardShortcuts([
{ keys: ["ctrl", "a"], onEvent: event => alert("ctrl + a was pressed") },
{ keys: ["shift", "b"], onEvent: event => alert("shift + b was pressed") },
{ keys: ["Tab"], handleNext },
{ keys: ["Esc"], handleClose },
{ keys: ["Enter"], handleSubmit, preventDefault: false },
])
useKeyboardShortcuts(
[{ keys: ["ctrl", "shift"], onEvent: () => alert('ctrl + shift + scroll is active') }],
true,
[],
"mousewheel"
)
}
keydown
and mousewheel
eventsctrl + a
and ctrl + shift + a
in the same hook, then the action
for ctrl + a
will not trigger when pressing ctrl + shift + a
.$ npm install --save use-keyboard-shortcuts
$ yarn add use-keyboard-shortcuts
import React from "react"
import useKeyboardShortcuts from "use-keyboard-shortcuts"
const Example = () => {
const [isOpen, setIsOpen] = React.useState(false)
useKeyboardShortcuts([
{ keys: ["ctrl", "a"], onEvent: event => alert("ctrl + a was pressed") },
{ keys: ["Esc"], onEvent: () => setIsOpen(false) },
])
return <div>...</div>
}
Argument (in order) | Type | Default | Description |
---|---|---|---|
shortcuts | Shortcut[] | undefined | Array of Shortcut -objects that should listen to the specified dependencies and eventType . See Shortcut object-section. |
active | boolean | true | Disables or enables all shortcuts. |
dependencies | any[] | [] | List dependencies of the shortcuts |
eventType | "keydown" /"mousewheel" | "keydown" | Wether it should listen for keyboard or mouse scroll events |
Key | Type | Description |
---|---|---|
keys | string[] | Combination of keys that needs to be pressed to trigger onEvent() . |
onEvent | function(event) | Action for when combination in keys are pressed. |
disabled | boolean | Used to disable a shortcut in particular |
See the example-folder for an extended example of how to use this hook with the mousewheel
event type.
MIT � SAITS
FAQs
React hook to attach keyboard shortcuts to the document
The npm package use-keyboard-shortcuts receives a total of 1,040 weekly downloads. As such, use-keyboard-shortcuts popularity was classified as popular.
We found that use-keyboard-shortcuts demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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.
Research
Security News
Socket uncovers an npm Trojan stealing crypto wallets and BullX credentials via obfuscated code and Telegram exfiltration.
Research
Security News
Malicious npm packages posing as developer tools target macOS Cursor IDE users, stealing credentials and modifying files to gain persistent backdoor access.
Security News
AI-generated slop reports are making bug bounty triage harder, wasting maintainer time, and straining trust in vulnerability disclosure programs.