A ~2kb hotkeys library for solid that adds only 2 event listeners.

Overview

Solid Hotkeys - Cmd+S+H

Solid Hotkeys Banner

Nodei.co badge

NPM version NPM downloads

Solid Hotkeys is the easiest way to add hotkeys to your application. Built for and with Solid.

Motivation

You gotta have hotkeys in your app. It doesn't use timeouts and other stuff like that, but rather checks if the keys currently are pressed and in the right order.

Gotchas

This library uses OPTIMISTIC DEFAULT PREVANTION or ODP - YEAH YOU KNOW ME. Which basically means if you have a hotkey with the keys META+S+D, everything before that will have it's default behaviour prevented.

Installation

There are a couple of things you need to do to install Hotkeys.

# yarn
yarn add solid-hotkeys

# npm
npm i solid-hotkeys

and presto you can get to hotkeying.

Usage

The API is pretty simple and extensively typed, so it's going to be really hard to mess it up, but here are a couple of examples:

Prerequisites

Register the useHotkeys hook in your app.

render(() => {
  useHotkeys();
  return <div />;
}, document.getElementById('root') as HTMLElement);

Basic

const opposite = (prev: boolean) => !prev;

const Basic = () => {
  const [show, setShow] = createSignal(false);

  createHotkey(['META', 'S'], event => {
    event.preventDefault();
    setShow(true);
  });

  return (
    <Show when={show()} fallback={"I'm not shown"}>
      I'm shown now
    </Show>
  );
};

NOTE: THE CURRENTLY PRESSED KEYS ARE ALL UPPERCASE BECAUSE OF NORMALIZATION

  • it has full types, so it'll be pretty easy to adjust

Types

You can also import the types so you can have stricter typing in your app!

import type {
  HotkeyArray,
  NormalizedKeys,
  HotkeyEvent,
  HotkeyCallback,
} from 'solid-hotkeys';
  • HotkeyArray -> what useHotkeys expects -> an array of all the normalized keys
  • Normalized Keys -> All of the keys that are maybe on a keyboard, uppercased
  • HotkeyEvent -> a stricter event where keys are strictly typed.
  • HotkeyCallback -> what the callback for the createHotkey function is

Closing notes

Report bugs, features and such and let's get this party started.

Cheers, -Alek

You might also like...

The 2Kb smallest Chat component.

The 2Kb smallest Chat component.

tidi Meet tidi, the 2kb bubble chat component for any website... made using preact, running with a 4MB compiled backend service. FrontEnd Backend Disc

Dec 11, 2022

Avoid use of dangerouslySetInnerHTML with this lightweight (2KB) function.

Avoid use of dangerouslySetInnerHTML with this lightweight (2KB) function. Can parse HTML strings into VDom trees, ready to render in your Preact components

May 14, 2022

Lightweight vanilla js modal component (just 2kb) , pure javascript Modal

Lightweight vanilla js modal component (just 2kb) pure javascript Modal , This is just 2kb Lightweight vanilla js modal component with zero dependenci

Dec 12, 2022

🦾 Tiny 2kb Markdown parser written, almost as fast and smart as Tony Stark

Starkdown 🦾 Starkdown is a Tiny 2kb Markdown parser written, almost as fast and smart as Tony Stark. npm i starkdown Motivation It is a continuation

Sep 22, 2022

🌈 GitHub following, followers, only-following, only-follower tracker 🌈

🌈 GitHub following, followers, only-following, only-follower tracker 🌈

github-following-tracker GitHub following, followers, only-following, only-follower tracker 👀 Just enter your GitHub name and track your followings!

Jun 15, 2022

Solid.js library adding a services layer for global shared state.

Solid.js library adding a services layer for global shared state.

Solid Services Services are "global" objects useful for features that require shared state or persistent connections. Example uses of services might i

Dec 30, 2022

Solid component and library for LiveKit (unofficial)

 Solid component and library for LiveKit (unofficial)

This package provides Solid components that makes it easier to use LiveKit in a Solid app. Inspired completely by https://github.com/livekit/livekit-r

Mar 8, 2022

hCaptcha Component Library for Solid.

Solid hCaptcha Component Library This is a port of @hcaptcha/react-hcaptcha for Solid. Description hCaptcha is a drop-replacement for reCAPTCHA that p

Dec 4, 2022

UI component library for Solid.js with SSR support

Dolmen Dolmen is a themeable UI component library designed to work with Solid.js and optimized for SSR (Server-side rendering). It provides a broad se

Dec 17, 2022
Comments
  • Error installing dependencies

    Error installing dependencies

    I'm getting an error when trying to install dependencies after git cloning the repo. Both on yarn and pnpm (why do you have lock files for both?) I'm on windows btw

    error C:\Users\gthet\Repositories\solid-hotkeys\node_modules\iltorb: Command failed.
    Exit code: 1
    Command: node ./scripts/install.js || node-gyp rebuild
    

    image

    The deps are getting installed, it's only crashing some script execution after installation, so I can run scripts.

    opened by thetarnav 0
Owner
Alek Angelov
I'm a shitty coder, I just kinda know how to solve problems.
Alek Angelov
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
To keep online organized data and be able to add listeners in certain paths by socket.io and http clients

The purpose of this project is to create a state machine server to keep organized data and be able to add listeners with socket.io in specific paths and in addition to providing a possible form of messages between socket.io clients.

Manga 3 Mar 19, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
Simple hotkeys.

simple-hotkeys Options el - jQuery selector / jQuery Object / Node; If you want to bind hotkeys to dynamic adding element, please pass a selector as e

彩程设计 11 Aug 24, 2021
'event-driven' library aims to simplify building backends in an event driven style

'event-driven' library aims to simplify building backends in an event driven style(event driven architecture). For message broker, light weight Redis Stream is used and for event store, the well known NoSQL database, MongoDB, is used.

Sihoon Kim 11 Jan 4, 2023
Adds full-text search to Community Solid Server. Powered by atomic-server

Solid Search for Community Solid Server This is an extension / plugin for the Community Solid Server. It adds full-text search to the Community Solid

Ontola 4 Jun 6, 2022
io-ts Typed Event Bus for the runtime of your Node.js application. A core for any event-driven architecture based app.

Typed Event Bus Based on io-ts types, this bus provides a handy interface to publish and consume events in the current runtime of the Node.js process.

Konstantin Knyazev 3 May 23, 2022
Adds `long-press` event to the DOM in 1k of pure JavaScript

long-press-event A 1k script that adds a long-press event to the DOM using CustomEvent and pure JavaScript. Works in IE9+, Chrome, Firefox, Safari as

John Doherty 262 Jan 2, 2023
A lightweight (~2kB) library to create range sliders that can capture a value or a range of values with one or two drag handles

range-slider-input A lightweight (~2kB) library to create range sliders that can capture a value or a range of values with one or two drag handles. Ex

Utkarsh Verma 42 Dec 24, 2022