Key generator for macos keybinding system
Project description
Compose Key On Macos
gen-compose
- generates compose key keybindings for macos.
A compose key (sometimes called multi key) is a key on a computer keyboard that indicates that the following (usually 2 or more) keystrokes trigger the insertion of an alternate character, typically a precomposed character or a symbol. https://en.wikipedia.org/wiki/Compose_key
Compose keys lets you insert complex character by entering multiple characters in a succession:
<compose_key> + s + <
will insert š
Mac os doesn't come with a compose key feature built-in. However there's a short hack to make it work:
- Keys can be rebound in mac via
~/Library/KeyBindings/DefaultKeyBinding.dict
dictionary file. - The rebound keys can be chained like compose keys e.g. pressing
abcd
can be made to insertAlphaBetaCharlieDad
- Modifier keys cannot be rebound
With these three rules we can replicate compose key and even set it to work with a mod key!
Install
gen-compose
can be installed via python manager with py3.6+ versions:
$ pip3 install --user gen-compose
$ gencompose --help
Usage: gen-compose [OPTIONS] COMPOSE_DATA
Generate macos rebind file from compose json mapping
Options:
-r, --raw TEXT just keymap without prefix
--help Show this message and exit.
Preconfig
-
First lets fix modifier key issue by forcing modifier to be a character. For example to use
right_options
key we need to use karabiner elements and remap it to some unused key likenon_us_backslash
: -
Now we have the compose key ready: if we click right_options it should insert
§
character
However we cannot compose anything yet as we have no compose mappings yet. For that we need to modify keybindings dictionary located in~/Library/KeyBindings/DefaultKeyBinding.dict
.
It's written in some cryptic hard to edit format and here's wheregen-compose
comes in and lets you writeyaml
files instead!
Usage
- Create yaml mappings file (e.g.
mappings/readme.yaml
):cat: "(^≗ω≗^)" "+1": 👍 "-1": 👍 ":(": "my face is sad"
This map defines key combinations and texts that will be inserted, e.g.<compose_key><plus><number 1>
will insert thumbs up.
note: see mappings directory for some built in mappings - Using
gen-compose
we generated.dict
keybind file file from our yaml configuration:$ gen-compose mappings/readme.yaml {"§" = { "c" = { "a" = { "t" = ("insertText:", "(^≗ω≗^)"); }; }; "+" = { "1" = ("insertText:", "👍"); }; "-" = { "1" = ("insertText:", "👍"); }; ":" = { "(" = ("insertText:", "my face is sad"); }; };}
note: multiple mappings can be used to generate a single keymap:$ gen-compose map1.yaml map2.yaml
- Now save it directly to keybinds file:
$ gen-compose mappings/readme.yaml > ~/Library/KeyBindings/DefaultKeyBinding.dict
- Restart your programs and type
§+1
and you'll see👍
! - Customize your own mapping or see
/mappings
for some existing configurations and have fun!
note: Some programs need a hard reboot to take in the map, like kill -9
sort of reboot to start working.
Related Resources
https://github.com/gnarf/osx-compose-key
http://lolengine.net/blog/2012/06/17/compose-key-on-os-x
http://bob.cakebox.net/osxcompose.php
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for gen_compose-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 583ab1a2529964d7639d8b9d5a35750b517e80bc647bda70b64fc8c67291a1ca |
|
MD5 | dd6c264f88bb936cab4bae3afe7da2a8 |
|
BLAKE2b-256 | 255fa19c82a3edd6977dd939046c0b34a47c6e27ef47e2440bbfa2d0a1f5e48f |