fgr-araujo / vue-shortkey

Vue-ShortKey - The ultimate shortcut plugin to improve the UX
MIT License
889 stars 101 forks source link

Is there a way to register a "shortkey" without an element? #124

Closed AllanOricil closed 1 year ago

AllanOricil commented 3 years ago

I could not find a way to register a shortkey without an element using this lib.

To achieve the desired result I had to use an eventListener.

beforeMount(){
      window.addEventListener('keyup', (event) => {
        if(event.ctrlKey && event.key === 'f') this.onClickHideFormButton();
      })
},
destroyed(){
      window.removeEventListener('keyup');
}

It would be good if you could expose a method from your API to be used from the js. Like,

ìmport { mapShortKey } from 'vue-shortkey';
created(){
      mapShortKey(['ctrl', 'f'], () => {
        this.doSomething():
      })
}
surfjedi commented 3 years ago

Yeah I'd like this feature too

fgr-araujo commented 3 years ago

This can be interesting

sudofox commented 3 years ago

I need to be able to register and destroy shortkeys within a sub-component in my app as well as temporarily disable shortkeys used by the main component since I'm working on a social site with a painting app built in.

But yeah, a lot of things don't have buttons tied to them that would be useful to register/destroy