No project description provided
Project description
Map2
A python library that allows complex key remapping on Linux, written in Rust.
Warning: this is the experimental python branch, the API is likely to change, please don't be annoyed or wait until it's on master.
All of the functionality related to interacting with graphical elements such as getting the active window information is currently only supported on X11. Wayland support is planned but probably won't be added for some time.
For details check the documentation.
Important note:
The legacy version of map2 which used a custom scripting langauge is located
here.
Due to performance and growing requirements map2 now uses python for the user
scripts. Map2 itself is still written in rust and compiled for maximum
performance.
Examples
Map2 supports use cases ranging all the way from simple key remappings to using complex callbacks and variables.
import map2
# a reader intercepts all input from device file descriptiors
reader = map2.Reader(patterns=[
"/dev/input/by-id/usb-Logitech_USB_Receiver-if01-event-.*",
"/dev/input/by-id/usb-Logitech_G700s_Rechargeable_Gaming_Mouse_017DF9570007-.*-event-.*",
"/dev/input/by-path/pci-0000:03:00.0-usb-0:9:1.0-event-kbd",
])
# a writer is responsible for remapping and outputting the modified input event stream
# it attaches to a reader, meaning the event stream is piped through
writer = map2.Writer(reader)
# change the 'a' key to 'b'
writer.map_key("a", "b")
def hello_world():
print("hello world")
# type the text using the virtual keyboard
writer.send("some text{enter}")
# map the 'c' key to a callback function
writer.map("c", hello_world)
# a window object listens to changes in the currently active window
window = map2.Window()
# do something on window change
def on_window_change(active_window_class):
if active_window_class == "firefox"):
print("firefox is now the active window")
# map 'F1' to ctrl+'t' (open new browser tab)
writer.map_key("f1", "^t")
else:
print("firefox is not the active window")
# map 'F1' back
writer.map_key("f1", "f1")
}
# register the callback
window.on_window_change(on_window_change)
# keep running until terminated
map2.wait()
For more examples check the examples directory.
Getting started
tldr:
- find the input device file descriptors you want to grab
- write a script file for remapping the keys, pass the descriptors to a
new
reader
object, remap keys on a newwriter
object - run
$ python my_remapping_script.py
Detailed documentation is still being worked on, consult the example scripts.
Install
TODO this section
- add
etc/udev/rules.d/10-my-udev.rules
groupadd map2
# create "map2" group
KERNEL=="event*", SUBSYSTEM=="input", ATTRS{hid}=="MYDEV000", MODE="0644", GROUP="map2", SYMLINK+="input/mydevice"
# add yourself to the "map2" group
$ usermod -aG `whoami` map2
Arch Linux
Arch packages are not available yet for the python branch.
Other distributions
Build local package from cloned source:
- download the source code from this repository
- install maturin and rust
- build using
$ maturin build --release
- install using
$ pip install target/wheels/NAME_OF_WHEEL_FILE.whl
Documentation
Detailed documentation is still being worked on, consult the example scripts.
Feature roadmap
- finalize python branch
- documentation (async callbacks, public API, etc.)
- deploy python branch to package repos
- fd patterns file
- add tests
- AHK-style hotstrings
- escaped characters in strings and key sequences
- pre-packaged binaries for various distros
- mouse events
- Wayland support (someday)
Contributing
If you want to report bugs, add suggestions or help out with development please check the issues page and open an issue if it doesn't exist yet.
License
MIT
Authors
- shiro shiro@usagi.io
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Hashes for map2-2.0.1-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a2416070cb0b8ec99775770b04f8c8a507da2b082487fcfe048722509fdb5b6 |
|
MD5 | 474c4b9812d3636eb4cf05ac40eae106 |
|
BLAKE2b-256 | 962c00bbd8dc5809d1a444959dfb7f9a13e9286bf51c0ac0f68dab3806dc307e |
Hashes for map2-2.0.1-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0bf89b94072fc5f9f6254d1416fd1d8cafa5f77c5d6cb1b5b142c29615104b07 |
|
MD5 | eb74097369aa216139fab97d086cbdd0 |
|
BLAKE2b-256 | a2f26888540d0919f9016f1d358b1221eb40b6f85135dc921512acfab6e04956 |
Hashes for map2-2.0.1-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 118498ab3ec6ca78fc84513fe96c11958777f920358a2ad112a4e08a33337390 |
|
MD5 | 072f271c8d0665f99c62f86f2ae173b9 |
|
BLAKE2b-256 | 950c9b936b5b34bd544ff29def38d9f61c8f1f539efcbe3c066452a07b437356 |
Hashes for map2-2.0.1-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c2f4f345ae7473e5b34835880f848fef3bd0f59d379f086560613d23c8988d8 |
|
MD5 | 67850e486cf8bf4a7ac6ca076e777430 |
|
BLAKE2b-256 | 682f9e03a851a6d32aa6cc13dd0cd2d97add3d6f86732045fd6129457e771423 |
Hashes for map2-2.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c9a55f8c26fefb280e4dc6fc63d8a33d5180fc047c96da19794a73d7244d034 |
|
MD5 | 0b3697434a3a41455334a54289693800 |
|
BLAKE2b-256 | a1f9478244f30e0e40d79ba14ea89c3f057e7ee968cbd9a28bff34fe32faff7b |
Hashes for map2-2.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab5f868b75b8d6b7c725414464dbc094f23738e4249ab6c9449eac86ffeffdb3 |
|
MD5 | 47c0c7f7837c201018744ea7a89ba2de |
|
BLAKE2b-256 | 25aeceb0ef9a4671b52507e007b675ef6bd41d2f87a35e0da11341b05786ca43 |
Hashes for map2-2.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e9a0118cca7f31a5e3c2b8cce7adace95d7999c7da6d542572a35f30247e32a6 |
|
MD5 | 505089c3fd224afa66c0fcde5fe36482 |
|
BLAKE2b-256 | f554eedd6e17faee3d869c13efe05a0d6d51e18b599248f59478c23c83bb179a |
Hashes for map2-2.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 485177f82d942d7003a5bd64d41309ac59a4791b6d19595c4238fc6faa44214c |
|
MD5 | 36772a28baba4fd88973cc8ce61057c9 |
|
BLAKE2b-256 | 4cbae88dc61883523d5ea842897a15bd2e0d88a9809671add22405ab9a7a4247 |
Hashes for map2-2.0.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e5a3f55ef75a95b37b782b0e5bea541ac0c054d41007669885e8953a2b28e4c |
|
MD5 | 36e1f63b95ae450a3732a9d4372c82ee |
|
BLAKE2b-256 | 96d9bb9e7477fdb8de9bea03d16fd3f0ce2d4e4c21fe89d68d723e1734250ce2 |
Hashes for map2-2.0.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e18b6846cfd018a01c0a27818f25b2d21de53c5684ae02325a44fd13c8f5fc5 |
|
MD5 | ba02b42417e3ffc52e5f746f9e02c42f |
|
BLAKE2b-256 | b2a6697593f6061faea643066fde1eb9d9d63d7906f88ed8cdf7c974d9f80334 |