{"id":13801096,"url":"https://github.com/piranha/keybind","last_synced_at":"2025-06-23T21:35:29.950Z","repository":{"id":19187214,"uuid":"22420156","full_name":"piranha/keybind","owner":"piranha","description":"ClojureScript key bindings (shortcut) library","archived":false,"fork":false,"pushed_at":"2017-11-27T09:05:33.000Z","size":20,"stargazers_count":85,"open_issues_count":0,"forks_count":4,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-06-12T01:07:55.240Z","etag":null,"topics":["clojurescript","hotkey","hotkeys","shortcut","shortcuts"],"latest_commit_sha":null,"homepage":"","language":"Clojure","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/piranha.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-07-30T09:32:38.000Z","updated_at":"2024-09-23T09:03:47.000Z","dependencies_parsed_at":"2022-08-18T18:31:33.343Z","dependency_job_id":null,"html_url":"https://github.com/piranha/keybind","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/piranha/keybind","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piranha%2Fkeybind","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piranha%2Fkeybind/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piranha%2Fkeybind/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piranha%2Fkeybind/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/piranha","download_url":"https://codeload.github.com/piranha/keybind/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piranha%2Fkeybind/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261559780,"owners_count":23177272,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["clojurescript","hotkey","hotkeys","shortcut","shortcuts"],"created_at":"2024-08-04T00:01:19.436Z","updated_at":"2025-06-23T21:35:29.925Z","avatar_url":"https://github.com/piranha.png","language":"Clojure","funding_links":[],"categories":["Awesome ClojureScript"],"sub_categories":["Miscellaneous"],"readme":"# keybind\n\nSmall library to handle key bindings (shortcuts) in browser, for ClojureScript.\n\n## Features\n\n* Simple format for defining bindings\n* Emacs-like key sequences\n* Default modifier (`defmod` is parsed as `cmd` on OS X and `ctrl` elsewhere)\n\n## Changelog\n\n### 2.2.0\n\n- handle Emacs-style key bindings (like `C-M-x C-j`)\n\n### 2.1.0\n\n- added global `disable!`/`enable!` functions (see further for instructions)\n\n### 2.0.1\n\n- fixed binding to `-` (and `minus`), now if you need to bind to minus on\n  keypad, use `kpminus`.\n\n### 2.0.0\n\n- renamed `keybind` to `keybind.core`\n- cleaned up code a bit\n\n## Usage\n\nAdd this to your `:dependencies` vector:\n\n[![Clojars Project](http://clojars.org/keybind/latest-version.svg)](http://clojars.org/keybind)\n\nAnd then:\n\n```clj\n\n(require '[keybind.core :as key])\n\n(key/bind! \"ctrl-c\" ::my-trigger #(js/console.log \"Sequence fired properly\"))\n```\n\nwhere `\"ctrl-c\"` is a button sequence to register on, and `::my-trigger` is a key\nunique for this sequence - you can use this key to remove binding later on.\n\n### Format description\n\nIf you know Emacs' format, you're all set. Not exactly Emacs - I decided to\nresort to more common names of modifiers, though Emacs-style `C-` and `M-` are\nalso supported.\n\nIn other case, you have to provide a list of modifiers (some of `shift`, `ctrl`,\n`alt`, `win`, `cmd`, `defmod`), followed by a key name. All of those should be\nseparated by `-`, i.e.: `ctrl-k`, `alt-m`, `shift-r`.\n\nCombining few such \"chords\" in a sequence, like `ctrl-k ctrl-m`, will register a\nkey sequence. To trigger you have to press `ctrl` and `k` simultaneously,\nrelease them and then press `ctrl` and `m` simultaneously.\n\n**Note 1**: if you want to register on a big letter, use `shift-a`.\n\n**Note 2**: `ctrl-j` in most browsers opens a \"Downloads\" window. I have thoughts\nhow to prevent that (for the sequence `ctrl-t ctrl-j k` for example), but didn't\ndo anything yet. Report an issue if you have a problem with that.\n\n**Note 3**: looking at the [source][] as a reference for key names makes sense. :)\n\n[source]: https://github.com/piranha/keybind/blob/master/src/keybind/core.cljs\n\n## Examples\n\n```clojure\n(require '[keybind.core :as key])\n\n(defn some-mount-function [items current-item]\n  (key/bind! \"j\" ::next #(go-next items current-item))\n  (key/bind! \"shift-space\" ::prev #(go-prev items current-item))\n  (key/bind! \"C-c C-x j\" ::chord #(js/alert \"ever heard of emacs chords?\")))\n\n(defn some-unmount-function []\n  (key/unbind! \"j\" ::next)\n  (key/unbind! \"shift-space\" ::prev)\n  (key/unbind! \"C-c C-x j\" ::chord)\n  ;; or simply:\n  (key/unbind-all!))\n```\n\n## Disable key bindings temporarily\n\nYou 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:\n\n```clojure\n(defn some-reagent-component []\n  [:textarea\n    {:value \"some text\"\n     :on-change handle-change\n     :on-focus key/disable!\n     :on-blur key/enable!}]))\n```\n\n## How it works\n\nLibrary binds global key handler to check all keypresses. The reason for this is\nthat focus in browsers is often hard to handle and define properly, and most of\nthe time it makes no sense to bind against some element.\n\n## Bindings storage\n\nAlso, you have to be aware that `bind!` and `unbind!` use global `BINDINGS`\natom. If you want to use your own atom, just use `bind` and `unbind` versions\n(`swap!` your atom with them). You'll have to bind `dispatcher!` on your own\nthough.\n\nI was also thinking how would you have more than a single atom - if you want to\norganize some contexts (on one page you have one set of bindings and another\npage obviously has different actions and different bindings) - and it seems to\nme it's easier to just `reset!` one single atom with necessary bindings when\nit's necessary. That's why `BINDINGS` is public.\n\nOr just `bind!`/`unbind!` all the time, whatever floats your boat.\n\n## Issues\n\nPlease notify me if you don't understand something, I would like to improve\ndocumentation but not sure exactly what to do.\n\nPlus it isn't possible to have custom key modifiers right now. Ideally I'd like\nto have that, but right now we're limited to Shift/Control/Alt/Command.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpiranha%2Fkeybind","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpiranha%2Fkeybind","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpiranha%2Fkeybind/lists"}