All Projects → piranha → keybind

piranha / keybind

Licence: ISC license
ClojureScript key bindings (shortcut) library

Programming Languages

clojure
4091 projects
Makefile
30231 projects

Projects that are alternatives of or similar to keybind

Keymage
Yet Another JS Keybinding library
Stars: ✭ 325 (+282.35%)
Mutual labels:  hotkeys, shortcut, hotkey, shortcuts
hotkey
⌨️ cross-platform hotkey package
Stars: ✭ 82 (-3.53%)
Mutual labels:  hotkeys, shortcut, hotkey, shortcuts
Hotkeys
➷ A robust Javascript library for capturing keyboard input. It has no dependencies.
Stars: ✭ 5,165 (+5976.47%)
Mutual labels:  hotkeys, shortcut, hotkey, shortcuts
react-shortcut
Convenient React component that detects if the given key combination is pressed, and triggers a callback
Stars: ✭ 16 (-81.18%)
Mutual labels:  hotkeys, shortcut, hotkey, shortcuts
Xcactionbar
"Alfred for Xcode" plugin
Stars: ✭ 1,217 (+1331.76%)
Mutual labels:  shortcut, hotkey, shortcuts
react-hotkey-tooltip
A global Hotkey provider with built in tooltip for React
Stars: ✭ 34 (-60%)
Mutual labels:  hotkeys, shortcut, hotkey
Win Vind
Simple Vim Key Binder for Windows. You can operate Windows with keybindings like Vim.
Stars: ✭ 151 (+77.65%)
Mutual labels:  hotkeys, hotkey
Icanhazshortcut
simple shortcut manager for macOS
Stars: ✭ 204 (+140%)
Mutual labels:  hotkeys, shortcuts
Autohotkey
⚙️ My Autohotkey productivity suite that includes shortcuts, hotstrings, hotkeys, apps/utilities, AutoCorrect
Stars: ✭ 113 (+32.94%)
Mutual labels:  hotkeys, shortcut
webplayer-hotkeys
A Chrome extension that assigns hotkeys to play/pause, and switch musics (next and previous). Works with Spotify, Deezer, SoundCloud and Youtube
Stars: ✭ 16 (-81.18%)
Mutual labels:  hotkeys, hotkey
g910-gkey-macro-support
GKey support for Logitech G910 Keyboard on Linux
Stars: ✭ 85 (+0%)
Mutual labels:  hotkeys, shortcut
swhkd
Sxhkd clone for Wayland (works on TTY and X11 too) | mirrored at https://git.sr.ht/~shinyzenith/swhkd
Stars: ✭ 215 (+152.94%)
Mutual labels:  hotkeys, hotkey
Capslock Plus
An efficiency tool that provides various functions by enhancing the Caps Lock key into a modifier key.
Stars: ✭ 650 (+664.71%)
Mutual labels:  shortcut, hotkey
Python Shortcuts
Create Siri Shortcuts with Python
Stars: ✭ 525 (+517.65%)
Mutual labels:  shortcut, shortcuts
react-keyboard-shortcuts
A declarative library for handling hotkeys based on explicit priority in React applications
Stars: ✭ 23 (-72.94%)
Mutual labels:  hotkeys, shortcuts
React Hotkeys
React component to listen to keydown and keyup keyboard events, defining and dispatching keyboard shortcuts.
Stars: ✭ 279 (+228.24%)
Mutual labels:  hotkeys, shortcut
Electron Localshortcut
Add keyboard shortcuts locally to a BrowserWindow instance, without using a Menu
Stars: ✭ 366 (+330.59%)
Mutual labels:  shortcut, shortcuts
Magnet
Customize global hotkeys in macOS.
Stars: ✭ 324 (+281.18%)
Mutual labels:  shortcut, hotkey
Androidshortcuts
Example app for shortcuts
Stars: ✭ 335 (+294.12%)
Mutual labels:  shortcut, shortcuts
Hotkeys
🤖 A declarative library for handling hotkeys in Angular applications
Stars: ✭ 158 (+85.88%)
Mutual labels:  hotkeys, shortcuts

keybind

Small library to handle key bindings (shortcuts) in browser, for ClojureScript.

Features

  • Simple format for defining bindings
  • Emacs-like key sequences
  • Default modifier (defmod is parsed as cmd on OS X and ctrl elsewhere)

Changelog

2.2.0

  • handle Emacs-style key bindings (like C-M-x C-j)

2.1.0

  • added global disable!/enable! functions (see further for instructions)

2.0.1

  • fixed binding to - (and minus), now if you need to bind to minus on keypad, use kpminus.

2.0.0

  • renamed keybind to keybind.core
  • cleaned up code a bit

Usage

Add this to your :dependencies vector:

Clojars Project

And then:

(require '[keybind.core :as key])

(key/bind! "ctrl-c" ::my-trigger #(js/console.log "Sequence fired properly"))

where "ctrl-c" is a button sequence to register on, and ::my-trigger is a key unique for this sequence - you can use this key to remove binding later on.

Format description

If you know Emacs' format, you're all set. Not exactly Emacs - I decided to resort to more common names of modifiers, though Emacs-style C- and M- are also supported.

In other case, you have to provide a list of modifiers (some of shift, ctrl, alt, win, cmd, defmod), followed by a key name. All of those should be separated by -, i.e.: ctrl-k, alt-m, shift-r.

Combining few such "chords" in a sequence, like ctrl-k ctrl-m, will register a key sequence. To trigger you have to press ctrl and k simultaneously, release them and then press ctrl and m simultaneously.

Note 1: if you want to register on a big letter, use shift-a.

Note 2: ctrl-j in most browsers opens a "Downloads" window. I have thoughts how to prevent that (for the sequence ctrl-t ctrl-j k for example), but didn't do anything yet. Report an issue if you have a problem with that.

Note 3: looking at the source as a reference for key names makes sense. :)

Examples

(require '[keybind.core :as key])

(defn some-mount-function [items current-item]
  (key/bind! "j" ::next #(go-next items current-item))
  (key/bind! "shift-space" ::prev #(go-prev items current-item))
  (key/bind! "C-c C-x j" ::chord #(js/alert "ever heard of emacs chords?")))

(defn some-unmount-function []
  (key/unbind! "j" ::next)
  (key/unbind! "shift-space" ::prev)
  (key/unbind! "C-c C-x j" ::chord)
  ;; or simply:
  (key/unbind-all!))

Disable key bindings temporarily

You may want to disable key bindings without actually removing them (e.g. while focus is on input/textarea elements). This can be accomplished via the disable! and enable! functions which don't affect the registration of bindings but simply control the dispatching of key events:

(defn some-reagent-component []
  [:textarea
    {:value "some text"
     :on-change handle-change
     :on-focus key/disable!
     :on-blur key/enable!}]))

How it works

Library binds global key handler to check all keypresses. The reason for this is that focus in browsers is often hard to handle and define properly, and most of the time it makes no sense to bind against some element.

Bindings storage

Also, you have to be aware that bind! and unbind! use global BINDINGS atom. If you want to use your own atom, just use bind and unbind versions (swap! your atom with them). You'll have to bind dispatcher! on your own though.

I was also thinking how would you have more than a single atom - if you want to organize some contexts (on one page you have one set of bindings and another page obviously has different actions and different bindings) - and it seems to me it's easier to just reset! one single atom with necessary bindings when it's necessary. That's why BINDINGS is public.

Or just bind!/unbind! all the time, whatever floats your boat.

Issues

Please notify me if you don't understand something, I would like to improve documentation but not sure exactly what to do.

Plus it isn't possible to have custom key modifiers right now. Ideally I'd like to have that, but right now we're limited to Shift/Control/Alt/Command.

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].