
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
keydown-key
Advanced tools
An utility to normalize the KeyboardEvent.key especially during IME composition
To address the inconsistent behavior of IME across different browsers and platforms:
When selecting a CJK character using the Enter key with IME, the keyDownEvent.key
value varies depending on the platform and browser combination.
keyDown.key
Issue in Chrome on MacExample: Screenshot
keyDown.key
Values with IMEChrome:
key === "Enter"
key === "Process"
Firefox:
key === "Process"
on both Mac and WindowsThis discrepancy can cause inconsistencies when handling keyboard events in web applications.
yarn add keydown-key
keydown-key
in your applicationimport keyDownKey from 'keydown-key';
// ... omit
function handleKeyDown(event: KeyboardEvent) {
const { key } = keyDownKey(event);
switch(key) {
case 'Enter':
// Do what you want for real `Enter` key
break;
case 'Process':
// The keyDown on "Enter" with IME will be here
break;
default:
}
}
inputBox.addEventListener('keydown', handleKeyDown);
import React from "react";
import keydownKey from "keydown-key";
const handleKeyDown = (event: React.KeyboardEvent) => {
// use the `nativeEvent` attribute to get the browser KeyboardEvent
// https://reactjs.org/docs/events.html#overview
const { key } = keydownKey(event.nativeEvent);
switch(key) {
case 'Enter':
// Do what you want for real `Enter` key
break;
case 'Process':
// The keyDown on "Enter" with IME will be here
break;
default:
}
};
const App = () => {
return <input onKeyDown={handleKeyDown} />;
};
export default App;
[1] IME https://en.wikipedia.org/wiki/Input_method
[2] CJK characters https://en.wikipedia.org/wiki/CJK_characters
[3] add support for SyntheticKeyboardEvent#isComposing https://github.com/facebook/react/issues/13104
[4] Support IME https://github.com/seawind543/react-token-input/issues/1#issuecomment-896190656
[5] Element: keydown event https://developer.mozilla.org/en-US/docs/Web/API/Document/keydown_event#ignoring_keydown_during_ime_composition
FAQs
An utility to normalize the KeyboardEvent.key especially during IME
The npm package keydown-key receives a total of 3,880 weekly downloads. As such, keydown-key popularity was classified as popular.
We found that keydown-key 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.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.