npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@adariari/vue3-keyregister

v0.2.1

Published

Vue 3 plugin to register and unregister key sequences. rather than pressing keys at the same time, you can execute a callback after pressing keys in certain sequence. such as h then e then l then l then o.

Downloads

5

Readme

Vue 3 Key Register

Vue 3 plugin to register and unregister key sequences. rather than pressing keys at the same time, you can execute a callback after pressing keys in certain sequence. such as h then e then l then l then o.

installation

npm install @adariari/vue3-keyregister

then in main.ts/main.js, add:

import KeyRegister from '@adariari/vue3-keyregister'
...
.use(KeyRegister)

Full example of main.js

import { createApp } from 'vue'
import App from './App.vue'
import KeyRegister from '@adariari/vue3-keyregister'


createApp(App)
    .use(KeyRegister)
    .mount('#app')

Example of use

<script setup>
    import { ref } from 'vue'
    // import composable useKeyRegister to register keys and change options
    import { useKeyRegister } from '@adariari/vue3-keyregister'

    const keyPressed = ref('');

    //register sequence hello,  and execute callback
    useKeyRegister().registerKeySequence({
        keyIdentity: 'h+e+l+l+o',
        callback: (key) => {
            console.log(key);
            keyPressed.value = key;
        }
    })

    //register sequence bye
    useKeyRegister().registerKeySequence({
        keyIdentity: 'b+y+e',
        callback: (key) => {
            console.log(key);
            keyPressed.value = key;
        }
    })
</script>


<template>
  key pressed : {{ keyPressed }}
</template>

Methods

RegisterKeySequence

useKeyRegister().registerKeySequence (
    RegisteryProps: object
)

RegistryProps can accept following options:

/*
     @key string keyIdentity unique identity of key sequence such as 'hello' or 'bye', maybe used as key|identity
     @key string key sequence of keys such as 'ctrl+shift+alt+key' or m+m or c+a
     @key boolean once if true, callback will be executed only once
     @key function callback (targetKey : string, lastEvent : KeyboardEvent) => void
     @key function|null validateTargetCallback callback to validate target
*/

key Or keyIdentity required callback also required

keyIdentity can be used as identity only, or to specifiy key e.g.

keyIdentity: "c+c|my cc key"

this both sets key as c+c and use keyIdentity c+c|my cc key

or you can set them separately:

key: "c+c",
keyIdentity: "my cc key"

you can also just set the key, but cautious that when you remove the key in this case, it will remove all mentions of it from any component

unregisterKeySequence

This can unregister the sequence by keyIdentity, it will remove any registered key matching the identity

useKeyRegister().unregisterKeySequence("c+c|my cc key");

registerSequenceListener

Register a listener for sequences, to customize action and process. return true if there is match or false if none

useKeyRegister().registerSequenceListener (
    ListenProps: object
)

ListenProps can accept following options:

/*
    @key options ListenerProps consists of 
            listener a callback that should take 
            (sequence : array<string> containing sequence of keys, lastEvent : KeyboardEvent) => boolean
            Boolean value should be returned to indicate if the sequence is matched
    @key Once if true, listener will be executed only once
*/

unregisterSequenceListener

Unregister listener

/*
@param listener to be unregistered
*/
You should pass same function you passed to register listener


## Options

You can set options globally either in main or in any component using composable

Available options:

```yml
// Timeout in milliseconds to wait for the next keypress
timeout: 500,
// Timeout in milliseconds to block key events after a key sequence is matched
blockingDelay: 10,

composable

const { options } = useKeyRegister();

//can set global timeout for all key sequences
options.timeout = 1000;

main

const app = createApp(App);
app.use(KeyRegister,{
    // Timeout in milliseconds to wait for the next keypress
    timeout: 500,
    // Timeout in milliseconds to block key events after a key sequence is matched
    blockingDelay: 10,
});
app.mount('#app');