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

shorte

v1.0.1

Published

Shortcut mode toggler for Electron

Downloads

7

Readme

ShortE

Keyboard shortcut modes for Electron

Build Status Coverage Status Standard - JavaScript Style Guide

Description

This allows you to designate a 'leader' key, that enters the user into a different 'mode'. Upon entering the new mode:

  • Your pre-defined shortcuts are registered and available to the user.
  • When using one of those shortcuts, a debouncing timer starts, at the end of which the user will return to the previous mode.
  • The user can press the 'cancel' shortcut to return to the previous mode.

Installation

npm install shorte

Usage

const ShortE = require('shorte')
const { globalShortcut } = require('electron')
// ...
app.on('ready', () => {
  const shortcuts = new ShortE(
    globalShortcut, // pass the electron globalShortcut object
    'Ctrl+B', // the initial leader key, this can be changed later
    { // opts
      debounceTime: 500 // default 0
      cancel: 'Ctrl+A' // default is Esc
    }
  )
  shortcuts.register('W', () => console.log('W was pressed'))
  shortcuts.register('Alt+B', () => console.log('Alt+B was pressed'))
  // Pressing: Ctrl+B + <indefinite wait> + W will print 'W was pressed'
  // Pressing: Ctrl+B + <indefinite wait> + Alt+B will print'Alt+B was pressed'
  // Pressing: 
  // Ctrl+B + <indefinite wait> + W + <wait less than 0.5 seconds> + Alt+B 
  // will print 'W was pressed' and 'Alt+B was pressed'
})

API

contructor

const shortcuts = new ShortE(globalShortcut, leader, opts)

Cteates the shortcuts object and registers the leader key.

  • globalShortcut - the electron globalShortcut object
  • leader - the leader key (electron Accelerator format) (eg. 'Ctrl+B')
  • opts - optional object including:
    • debounceTime (in milliseconds) - default is 0
    • cancel - string for custom button - default is Esc

register

shortcuts.register(key, cb)

Registers a shortcut key. Once the leader key will be pressed, this shortcut will be available.

  • key: The key combination in electron Accelerator format. (eg. 'Alt+B')
  • cb: The function to be called when this key is pressed.

leader

shortcuts.leader(key)

Changes the leader key.

  • key: the new leader key

cancel

shortcuts.cancel(key)

Changes the cancel key.

  • key: the new cancel key

Accessors

debounceTime

console.log(shortcuts.debounceTime) // 500
shortcuts.debounceTime = 100
console.log(shortcuts.debounceTime) // 100

shortcuts

console.log(shortcuts.shortcuts) // { a: [ some function ], b: [ some other function] }
shortcuts.shortcuts.a = function () => {} // silently fail

active

// Press leader key
console.log(shortcuts.active) // true
// Press a shortcut, wait debounceTime
console.log(shortcuts.active) // false

Events

active

shortcuts.on('active', () => console.log('leader key pressed, shortcuts now available'))
// Press leader key
// 'leader key pressed, shortcuts now available

inactive

shortcuts.on('inactive', () => console.log('timeout reached, shortcuts unavailable'))
// Press leader key
// Use shortcut and wait debounce time, or press cancel key
// 'timeout reached, shortcuts unavailable'

Contributing

Yes please.

License

MIT