Skip to main content

A dynamic keyboard remapper for Wayland.

Project description

test PyPI version

wayremap

Dynamic keyboard remapper for Wayland.

It works on both X Window Manager and Wayland, but focused on Wayland as it intercepts evdev input and require root permission.

Motivation

Wayland and Sway is awesome. It brings lots of benefit to Linux desktop environment.

When I was using X desktop envionment, there is an awesome tool called xremap which remap keys based on current focused application.

https://github.com/k0kubun/xremap

I was looking for something similar to xremap for Wayland, but not found, so I decided to create on my own.

Install

sudo pip install wayremap

# For beta version
sudo pip3 install git+https://github.com/acro5piano/wayremap

Run

For Wayland security model, we have to run keyboard remapping tools as root permission.

Simply write your own service and run it as a python script:

 # /etc/wayremap.config.py

from wayremap import ecodes as e, run, WayremapConfig, Binding, wait_sway
import uinput as k

wayremap_config = WayremapConfig(
    # Note that `'/dev/input/event4'` varies among system.
    input_path='/dev/input/event4',

    # Filter applications which remap will be applied
    applications=[
        'Chromium',
        'Brave-browser',
        'Leafpad',
        'firefoxdeveloperedition',
    ],

    bindings=[
        # To see all available binding keys, please see
        # https://github.com/acro5piano/wayremap/blob/06d27c9bb86b766d7fd1e4230f3a16827785519e/wayremap/ecodes.py
        # modifier keys are `KEY_LEFTCTRL` or `KEY_LEFTALT`, or both. Neither `shift` nor `super` is not implemented yet.

        # Emacs-like key binding
        Binding([e.KEY_LEFTCTRL, e.KEY_LEFTALT, e.KEY_A],
                [[k.KEY_LEFTCTRL, k.KEY_HOME]]),
        Binding([e.KEY_LEFTCTRL, e.KEY_LEFTALT, e.KEY_E],
                [[k.KEY_LEFTCTRL, k.KEY_END]]),
        Binding([e.KEY_LEFTCTRL, e.KEY_LEFTALT, e.KEY_H],
                [[k.KEY_LEFTCTRL, k.KEY_BACKSPACE]]),
        Binding([e.KEY_LEFTCTRL, e.KEY_F], [[k.KEY_RIGHT]]),
        Binding([e.KEY_LEFTCTRL, e.KEY_B], [[k.KEY_LEFT]]),
        Binding([e.KEY_LEFTCTRL, e.KEY_P], [[k.KEY_UP]]),
        Binding([e.KEY_LEFTCTRL, e.KEY_N], [[k.KEY_DOWN]]),
        Binding([e.KEY_LEFTCTRL, e.KEY_K],
                [[k.KEY_LEFTSHIFT, k.KEY_END], [k.KEY_LEFTCTRL, k.KEY_X]]),
        Binding([e.KEY_LEFTCTRL, e.KEY_A], [[k.KEY_HOME]]),
        Binding([e.KEY_LEFTCTRL, e.KEY_E], [[k.KEY_END]]),
        Binding([e.KEY_LEFTCTRL, e.KEY_Y], [[k.KEY_LEFTCTRL, k.KEY_V]]),
        Binding([e.KEY_LEFTALT, e.KEY_F], [[k.KEY_LEFTCTRL, k.KEY_RIGHT]]),
        Binding([e.KEY_LEFTALT, e.KEY_B], [[k.KEY_LEFTCTRL, k.KEY_LEFT]]),
        Binding([e.KEY_LEFTALT, e.KEY_D], [[k.KEY_LEFTCTRL, k.KEY_DELETE]]),
        Binding([e.KEY_LEFTCTRL, e.KEY_H], [[k.KEY_BACKSPACE]]),
        Binding([e.KEY_LEFTCTRL, e.KEY_D], [[k.KEY_DELETE]]),
        Binding([e.KEY_LEFTCTRL, e.KEY_S], [[k.KEY_LEFTCTRL, k.KEY_F]]),


        # OSX-like key binding
        Binding([e.KEY_LEFTALT, e.KEY_A], [[k.KEY_LEFTCTRL, k.KEY_A]]),
        Binding([e.KEY_LEFTALT, e.KEY_C], [[k.KEY_LEFTCTRL, k.KEY_C]]),
        Binding([e.KEY_LEFTALT, e.KEY_V], [[k.KEY_LEFTCTRL, k.KEY_V]]),

        # Slack helm!
        Binding([e.KEY_LEFTALT, e.KEY_X], [[k.KEY_LEFTCTRL, k.KEY_K]]),
    ])


# Required if you want to use wayremap as a startup service.
wait_sway()

# Finally, run wayremap.
run(wayremap_config)

And then

sudo modprobe uinput
sudo python /opt/wayremap.py

Enable wayremap as a systemd service

echo uinput | sudo tee /etc/modules-load.d/wayremap.conf # Add uinput to auto-loaded linux modules
sudo vim /etc/wayremap.config.py # Edit your config
sudo cp ./systemd/wayremap.service /etc/systemd/system/wayremap.service
sudo systemctl enable wayremap
sudo reboot

Known bugs

  • 3 is pressed when changing focused window → Fixed now
  • Key repeating become slow while switching focused windowd

Roadmap

  • Enable to run wihtout Sway.
  • Support shift and super keys too.
  • Packaging for Arch Linux, Debian, Fedora, etc.
  • Enable to load per-application config.
  • Re-write in Rust for better performance.

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

wayremap-0.0.10.tar.gz (13.3 kB view details)

Uploaded Source

Built Distribution

wayremap-0.0.10-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file wayremap-0.0.10.tar.gz.

File metadata

  • Download URL: wayremap-0.0.10.tar.gz
  • Upload date:
  • Size: 13.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.10.2 Linux/5.16.8-arch1-1

File hashes

Hashes for wayremap-0.0.10.tar.gz
Algorithm Hash digest
SHA256 775c55e42359dd24b13859d0c553e030aba9c11d13fba4550aef09fbba955d6f
MD5 0f7725923b09cc6b002f9ae4f8714a3a
BLAKE2b-256 7918c372fe2f109ebd960060e676c98224c00953f64001acf8dd912daf9eeed7

See more details on using hashes here.

File details

Details for the file wayremap-0.0.10-py3-none-any.whl.

File metadata

  • Download URL: wayremap-0.0.10-py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.10.2 Linux/5.16.8-arch1-1

File hashes

Hashes for wayremap-0.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 6ed03dfb4bfe595f2a70577c71f3a440a357f156d235323310855243d019e2d1
MD5 cf931f61f016e72e528d7bc8dd121ce1
BLAKE2b-256 9f1b2363c9f9d5d99456fe75b9734ef97fbe22659781849f983907b65cf04639

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page