All Projects → iFgR → Vue Shortkey

iFgR / Vue Shortkey

Licence: mit
Vue-ShortKey - The ultimate shortcut plugin to improve the UX

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Vue Shortkey

ShortcutJS
Keyboard manager for javascript and typescript, made for humans 😎
Stars: ✭ 26 (-96.43%)
Mutual labels:  shortcut
Magnet
Customize global hotkeys in macOS.
Stars: ✭ 324 (-55.49%)
Mutual labels:  shortcut
Bash Shortcuts Cheat Sheet
Useful shortcuts for bash/zsh
Stars: ✭ 452 (-37.91%)
Mutual labels:  shortcut
react-hotkey-tooltip
A global Hotkey provider with built in tooltip for React
Stars: ✭ 34 (-95.33%)
Mutual labels:  shortcut
Codeexpander
A cross-platform cloud synchronization development tool for developers that includes input enhancement, code snippet management, and Markdown. (专为开发者开发的一个集输入增强、代码片段管理(支持 Markdown)为一体跨平台云同步的开发工具。)
Stars: ✭ 285 (-60.85%)
Mutual labels:  shortcut
Androidshortcuts
Example app for shortcuts
Stars: ✭ 335 (-53.98%)
Mutual labels:  shortcut
hotscript
HotScript - Revolutionizing how Windows works.
Stars: ✭ 29 (-96.02%)
Mutual labels:  shortcut
Hotkey
Simple global shortcuts in macOS
Stars: ✭ 574 (-21.15%)
Mutual labels:  shortcut
Pixel Picker
A tiny menu bar application that helps you pick colours from your screen! 🔍✨
Stars: ✭ 318 (-56.32%)
Mutual labels:  shortcut
Pretzel
Pretzel is Mac desktop app that shows and find keyboard shortcuts based on your current app.
Stars: ✭ 405 (-44.37%)
Mutual labels:  shortcut
ShortcutMapper Chinese
可视化、交互式的快捷键映射图,中文版本,可以直观地查找快捷键。不懂编程也可以方便地修改、添加快捷键。
Stars: ✭ 23 (-96.84%)
Mutual labels:  shortcut
React Hotkeys
React component to listen to keydown and keyup keyboard events, defining and dispatching keyboard shortcuts.
Stars: ✭ 279 (-61.68%)
Mutual labels:  shortcut
Electron Localshortcut
Add keyboard shortcuts locally to a BrowserWindow instance, without using a Menu
Stars: ✭ 366 (-49.73%)
Mutual labels:  shortcut
gh-omnibar
[Deprecated(use github's`/` instead, you're welcome github)] Github Omnibar Extension for Firefox and Chrome
Stars: ✭ 72 (-90.11%)
Mutual labels:  shortcut
Python Shortcuts
Create Siri Shortcuts with Python
Stars: ✭ 525 (-27.88%)
Mutual labels:  shortcut
apptivator
A macOS menubar app which activates applications via global shorcuts ⌨️
Stars: ✭ 72 (-90.11%)
Mutual labels:  shortcut
Keymage
Yet Another JS Keybinding library
Stars: ✭ 325 (-55.36%)
Mutual labels:  shortcut
Capslock Plus
An efficiency tool that provides various functions by enhancing the Caps Lock key into a modifier key.
Stars: ✭ 650 (-10.71%)
Mutual labels:  shortcut
Hotkeys
➷ A robust Javascript library for capturing keyboard input. It has no dependencies.
Stars: ✭ 5,165 (+609.48%)
Mutual labels:  shortcut
Bluetoothconnector
Simple macOS CLI to connect/disconnect a Bluetooth device. Useful for AirPods or other Bluetooth headphones.
Stars: ✭ 388 (-46.7%)
Mutual labels:  shortcut

vue-shortkey logo

CircleCI status npm version npm MIT Licence

Vue-ShortKey - plugin for VueJS 2.x accepts shortcuts globaly and in a single listener.

Install

npm install vue-shortkey --save

Usage

Vue.use(require('vue-shortkey'))

Add the shortkey directive to the elements that accept the shortcut. The shortkey must have explicitly which keys will be used.

Running functions

The code below ensures that the key combination ctrl + alt + o will perform the 'theAction' method.

<button v-shortkey="['ctrl', 'alt', 'o']" @shortkey="theAction()">Open</button>

The function in the modifier @shortkey will be called repeatedly while the key is pressed. To call the function only once, use the once modifier

<button v-shortkey.once="['ctrl', 'alt', 'o']" @shortkey="theAction()">Open</button>

Multi keys

<button v-shortkey="{up: ['arrowup'], down: ['arrowdown']}" @shortkey="theAction">Joystick</button>

... and your method will be called with the key in the parameter

methods: {
  theAction (event) {
    switch (event.srcKey) {
      case 'up':
        ...
        break
      case 'down':
        ...
        break

Setting the focus

You can point the focus with the shortcut easily. The code below reserves the ALT + I key to set the focus to the input element.

<input type="text" v-shortkey.focus="['alt', 'i']" v-model="name" />

Push button

Sometimes you may need a shortcut works as a push button. It calls the function one time when you click the button. When you release the shortcut, it calls the same function again like a toggle. In these cases, insert the "push" modifier.

The example below shows how to do this

<tooltip v-shortkey.push="['f3']" @shortkey="toggleToolTip"></tooltip>

Using on a component

Use the modifier native to catch the event.

 <my-component v-shortkey="['ctrl', 'alt', 'o']" @shortkey.native="theAction()"></my-component>

Multiple listeners

Use the modifier propagate to let the event propagate to other listeners

 <my-component v-shortkey="['ctrl', 'alt', 'o']" @shortkey.propagate="anAction()"></my-component>
 <my-component v-shortkey="['ctrl', 'alt', 'o']" @shortkey.propagate="aDifferentAction()"></my-component>

Key list

Key Shortkey Name
Delete del
Backspace backspace
Insert insert
NumLock numlock
CapsLock capslock
Pause pause
ContextMenu contextmenu
ScrollLock scrolllock
BrowserHome browserhome
MediaSelect mediaselect
Shift shift
Control ctrl
Alt alt
Alt Graph altgraph
Super (Windows or Mac Cmd) meta
Arrow Up arrowup
Arrow Down arrowdown
Arrow Left arrowleft
Arrow Right arrowright
Enter enter
Escape esc
Tab tab
Space space
Page Up pageup
Page Down pagedown
Home home
End end
A - Z a-z
0-9 0-9
F1-F12 f1-f12

You can make any combination of keys as well as reserve a single key.

<input type="text" v-shortkey="['q']" @shortkey="foo()"/>
<button v-shortkey="['ctrl', 'p']" @shortkey="bar()"></button>
<button v-shortkey="['f1']" @shortkey="help()"></button>
<textarea v-shortkey="['ctrl', 'v']" @shortkey="dontPaste()"></textarea>

Avoided fields

You can avoid shortcuts within fields if you really need it. This can be done in two ways:

  • Preventing a given element from executing the shortcut by adding the v-shortkey.avoid tag in the body of the element
<textarea v-shortkey.avoid></textaea>
  • Generalizing type of element that will not perform shortcut. To do this, insert a list of elements in the global method.
Vue.use('vue-shortkey', { prevent: ['input', 'textarea'] })
  • Or even by class
Vue.use('vue-shortkey', { prevent: ['.my-class-name', 'textarea.class-of-textarea'] })

Other uses

With the dynamism offered by Vue, you can easily create shortcuts dynamically

<li v-for="(ctx, item) in items">
  <a
    href="https://vuejs.org"
    target="_blank"
    v-shortkey="['f' + (item + 1)]"
    @shortkey="testa(item)"
    @click="testa()">
      F {{ item }}
  </a>
</li>

Integrating with Nuxt

Create /plugins/vue-shortkey.js and add the following to it

import Vue from 'vue'
const ShortKey = require('vue-shortkey')

// add any custom shortkey config settings here
Vue.use(ShortKey, { prevent: ['input', 'textarea'] })

export default ShortKey

Load the plugin in nuxt.config.js:

plugins: [ { src: '@/plugins/vue-shortkey.js', mode: 'client' }]

The mode: 'client' is necessary to prevent Nuxt from loading the plugin during server-side rendering (SSR).

Unit Test

npm test
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].