@solid-primitives/keyboard
A library of reactive promitives helping handling user's keyboard input.
makeKeyHoldListener
- Attaches keyboard event-listeners, and triggers callback whenever user holds or stops holding specified key.
Installation
npm install @solid-primitives/keyboard
yarn add @solid-primitives/keyboard
makeKeyHoldListener
Attaches keyboard event-listeners to window
, and calls provided callback whenever user holds or stops holding specified key.
Event listeners are automatically cleaned on root dispose.
How to use it
makeKeyHoldListener
takes three arguments:
key
keyboard key or modifier to listen foronHoldChange
callback fired when the hold state changesoptions
additional configuration:
preventDefault
— call e.preventDefault()
on the keyboard event, when the specified key is pressed. (Defaults to false
)allowOtherKeys
— Should the user be allowed to press other keys while holding the specified one (Defaults to false
)
import { makeKeyHoldListener } from "@solid-primitives/keyboard";
const [pressing, setPressing] = createSignal(false);
makeKeyHoldListener("altKey", setPressing, {
preventDefault: true
});
<p>Is pressing Alt? {pressing() ? "YES" : "NO"}</p>;
Changelog
Expand Changelog
0.0.100
Initial release as a Stage-0 primitive.