Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
is-printable-key-event
Advanced tools
Detect whether a KeyboardEvent is caused by a printable key
Detect whether a DOM KeyboardEvent key event is printable; that is, typed by a user. This is useful for custom input components that need ignore control keys such as Alt
and only be triggered when 'regular', printable keys are pressed such as a
or €
.
Detecting whether a DOM UI event key is printable has become more complicated since KeyboardEvent.keyCode
was deprecated (see https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode), as you can no longer simply specify the ranges of printable key codes (an approach chosen by https://github.com/mynamesleon/is-printable-keycode).
Instead, we rely on the W3C UI Events KeyboardEvent specification to determine whether a keyboard event is caused by a printable key press. A printable key here is defined by the W3C spec as a "key string", i.e. a "character typed by the user". To do this, we check the event's key attribute against a list of known non-printable keys (called "named key attribute values"). If the key is not in this list, we determine it to be printable.
import isPrintableKeyEvent from "is-printable-key-event";
element.addEventListener("keydown", function (event) {
if (isPrintableKeyEvent(event) === false) {
return; // ignore key down
}
// do something with input
});
https://www.aarongreenlee.com/blog/list-of-non-printable-keys-for-keyboard-events-when-using-event-key/ https://www.w3.org/TR/uievents-key/
FAQs
Detect whether a KeyboardEvent is caused by a printable key
The npm package is-printable-key-event receives a total of 4,430 weekly downloads. As such, is-printable-key-event popularity was classified as popular.
We found that is-printable-key-event 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.