All Projects → houmain → keymapper

houmain / keymapper

Licence: GPL-3.0 license
A cross-platform context-aware key remapper.

Programming Languages

C++
36643 projects - #6 most used programming language
c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to keymapper

gnome-gesture-improvements
Touchpad gesture improvements for GNOME on Wayland/X11
Stars: ✭ 53 (+35.9%)
Mutual labels:  wayland, gnome-shell-extension
Shortcutmapper
A visual keyboard shortcuts explorer for popular applications.
Stars: ✭ 657 (+1584.62%)
Mutual labels:  keyboard-layout, keyboard-shortcuts
Evscript
A tiny sandboxed Dyon scripting environment for evdev input devices that lets you do e.g. xcape in Wayland
Stars: ✭ 91 (+133.33%)
Mutual labels:  keyboard-shortcuts, wayland
keyboard modifiers status
Gnome-Shell extension that shows keyboard modifiers status. It's useful when sticky keys are active.
Stars: ✭ 15 (-61.54%)
Mutual labels:  wayland, gnome-shell-extension
Hawck
Key-rebinding daemon for Linux (Wayland/X11/Console)
Stars: ✭ 198 (+407.69%)
Mutual labels:  keyboard-shortcuts, wayland
Video-Game-Keyboard-Database
A set of PHP forms and MySQL databases that generate keyboard control diagrams in a new browser window. You can select control bindings from among various video games and other software.
Stars: ✭ 38 (-2.56%)
Mutual labels:  keyboard-layout, keyboard-shortcuts
keyboard layout
Keyboard switcher for Awesome WM with additional layouts
Stars: ✭ 48 (+23.08%)
Mutual labels:  keyboard-layout
optimized-azerty-win
AFNOR Compliant AZERTY Keyboard Layout driver for Windows
Stars: ✭ 35 (-10.26%)
Mutual labels:  keyboard-layout
nextshot
A simple tool for taking screenshots on Linux and sharing via Nextcloud
Stars: ✭ 37 (-5.13%)
Mutual labels:  wayland
wayland-explorer
Easily browse and read Wayland protocols documentation
Stars: ✭ 78 (+100%)
Mutual labels:  wayland
earth-view-wallpaper-gnome-extension
A beautiful satellite image from Google Earth as your GNOME desktop wallpaper.
Stars: ✭ 48 (+23.08%)
Mutual labels:  gnome-shell-extension
compiz-alike-magic-lamp-effect
Compiz alike magic lamp effect for GNOME Shell
Stars: ✭ 58 (+48.72%)
Mutual labels:  gnome-shell-extension
kalamine
Keyboard Layout Maker
Stars: ✭ 47 (+20.51%)
Mutual labels:  keyboard-layout
python-wayland
Pure Python 3 Wayland protocol implementation
Stars: ✭ 23 (-41.03%)
Mutual labels:  wayland
gnome-pass-search-provider
Pass password manager search provider for gnome-shell
Stars: ✭ 52 (+33.33%)
Mutual labels:  gnome-shell-extension
gnome-runcat
😼 The cat tells you the CPU usage by running speed
Stars: ✭ 194 (+397.44%)
Mutual labels:  gnome-shell-extension
numbernine
Attempt at a desktop shell and stuff; abandoned in favor of https://github.com/DankBSD/waysmoke
Stars: ✭ 15 (-61.54%)
Mutual labels:  wayland
cliphist
wayland clipboard manager
Stars: ✭ 47 (+20.51%)
Mutual labels:  wayland
hubnav
A Chrome extension for navigating github.com via keyboard shortcuts. Quickly access issues for multiple repos, as well as your org's pages.
Stars: ✭ 96 (+146.15%)
Mutual labels:  keyboard-shortcuts
gnome-shell-extension-scroll-panel
Gnome Shell extension that allows to switch between workspaces and applications by scrolling mouse wheel above the top panel.
Stars: ✭ 23 (-41.03%)
Mutual labels:  gnome-shell-extension

keymapper

Build Issues

Configuration | Example | Functional principle | Installation | Building | Changelog

A cross-platform context-aware key remapper. It allows to:

  • Redefine keyboard shortcuts system-wide or per application.
  • Manage all your keyboard shortcuts in a single configuration file.
  • Change shortcuts for similar actions in different applications at once.
  • Share configuration files between multiple systems (GNU/Linux, Windows).
  • Bind keyboard shortcuts to terminal commands.

Configuration

Configuration files are easily written by hand and mostly consist of lines with input expressions and corresponding output expressions separated by >>:

# comments start with # or ; and continue until the end of a line
CapsLock >> Backspace
Z >> Y
Y >> Z
Control{Q} >> Alt{F4}

Unless overridden, using the command line argument -c, the configuration is read from:

  • on Linux:       $HOME/.config/keymapper.conf
  • on Windows: keymapper.conf in the working directory.

The command line argument -u causes the configuration to be automatically reloaded whenever the configuration file changes.

⚠️ In case of emergency: You can always press the special key combination Shift+Escape+K to terminate keymapper.

Key names

The keys are named after their scan codes and are not affected by the present keyboard layout. The names have been chosen to match on what the web browsers have agreed upon, so this handy website can be used to get a key's name. For convenience the letter and digits keys are also named A to Z and 0 to 9. The logical keys Shift, Control and Meta are also defined (each matches the left and right modifier keys). There are also virtual keys for state switching and an Any key.

⚠️ Beware that the configuration file is case sensitive.

Input expressions

Input expressions consist of one or more key names separated by spaces or parenthesis, which give them different meaning:

  • A B means that keys have to be pressed successively (released in any order).
  • (A B) means that keys have to be pressed simultaneously in any order.
  • A{B} means that a key has to be hold while another is pressed.
  • !A means that a key must not be pressed.
  • Groups and modifiers can also be nested like A{B{C}} or (A B){C}.

Output expressions

The output expression format is analogous to the input expression format:

  • A B means that keys are pressed successively.
  • (A B) means that both keys are pressed simultaneously.
  • A{B} means that a key is hold while another is pressed.
  • !A means that the (potentially pressed) key should be released before the rest of the expression is applied.
  • ^ splits the output in two parts, one which is applied when the input is pressed and one when it is released (see further explanation).
  • $() can be used for terminal command binding.
  • An empty expression can be used to suppress any output.

Order of mappings

Mappings are always applied in consecutive order, therefore their order is of importance. While the following outputs A as soon as Meta is pressed:

Meta    >> A
Meta{X} >> B

The other way round, nothing is output when Meta is pressed alone. Depending on whether an X follows, either B or A is output:

Meta{X} >> B
Meta    >> A

⚠️ You may want to start your configuration with mappings, which ensure that the common mouse-modifiers are never hold back:

Shift   >> Shift
Control >> Control
AltLeft >> AltLeft

For a detailed description of how the mapping is applied, see the Functional principle section.

Context awareness

Context blocks allow to enable mappings only in specific contexts. A context can be defined by system, window title or window class. They are opened like:

[system="Windows" title="..." class="..."]

A block continues until the next block (respectively the end of the file). The block which applies in all contexts can be reopened using default. e.g.:

[default]
CapsLock >> Backspace

[title="Visual Studio"]
Control{B} >> (Shift Control){B}

[system="Linux" class="qtcreator"]
...

The title filter matches windows containing the string in the title, the class filter only matches windows with the exact class name. For finer control regular expressions can be used. These have to be delimited with slashes. Optionally i can be appended to make the comparison case insensitive:

[title=/Visual Studio Code|Code OSS/i]

Additionally a common modifier for all the block's input expressions can be defined:

[modifier="CapsLock"]
K >> ArrowDown          # the same as "CapsLock{K} >> ArrowDown"

Abstract commands

To simplify mapping of one input expression to different output expressions, it can be mapped to an abstract command first. The command name can be chosen arbitrarily but must not be a key name. The configuration is case sensitive and all key names start with a capital letter, so it is advisable to begin command names with a lowercase letter:

Control{B} >> build

Subsequently this command can be mapped to one output expression per context. The last active mapping overrides the previous ones:

build >> Control{B}

[title="Visual Studio"]
build >> (Shift Control){B}

Output on key release

When an output expression contains ^, it is only applied up to this point, when the input key is pressed. The part after the ^ is not applied until the input is released. Both parts can be empty:

# send "cmd" after the Windows run dialog appeared
Meta{C} >> Meta{R} ^ C M D Enter

# prevent key repeat
A >> B^

# output B when A is released
A >> ^B

Virtual keys

Virtual0 to Virtual9 are virtual keys, which can be used as state switches. They are toggled when used in output expressions and can be used as modifiers in input expressions:

# Virtual1 is toggled whenever ScrollLock is pressed
ScrollLock >> Virtual1

# map A to B when Virtual1 is down
Virtual1{A} >> B

# map E to F when Virtual1 is NOT down
!Virtual1 E >> F

Any key

Any can be used in input and output expressions. In input expressions it matches any key and in output expressions it outputs the matched input.

# swap Control and Shift
Control{Any} >> Shift{Any}
Shift{Any} >> Control{Any}

This can for example be used to exclude an application from mapping:

[title="Remote Desktop"]
Any >> Any

[default]
...

Key aliases

For convenience aliases for keys and even sequences can be defined. e.g.:

Win = Meta
Boss = Virtual1
Alt = AltLeft | AltRight
FindNext = Control{F3}
Greet = H E L L O

Terminal command binding

$() can be used in output expressions to embed terminal commands, which should be executed when the output is triggered:

Meta{W} >> $(exo-open --launch WebBrowser) ^

⚠️ You may want to append ^ to ensure that the command is not executed repeatedly as long as the input is kept hold.

Example configuration

The author's personal configuration may serve as an inspiration (which itself took some inspiration from DreymaR's Big Bag Of Keyboard Tricks).

Functional principle

For advanced application it is good to know how the mapping is applied:

  • All key strokes are intercepted and appended to a key sequence.
  • On every key stroke the key sequence is matched with all input expressions in consecutive order, until an expression matches or might match (when more strokes follow). Mappings in inactive contexts are skipped.
  • When the key sequence can no longer match any input expression (because more strokes followed), the longest exact match is looked for (by ignoring the last strokes). As long as still nothing can match, the first strokes are removed and forwarded as output.
  • When an input expression matches, the key sequence is cleared and the mapped expression is output.
  • Keys which already matched but are still physically pressed participate in expression matching as an optional prefix to the key sequence.

Installation

Linux

On Linux the program is split into two parts:

  • keymapperd is the daemon which needs to be run as root or some other user who is authorized to grab the keyboard and inject keys.
  • keymapper loads the configuration, informs the daemon about it and the active context and also executes mapped terminal commands. It needs to be run as normal user within an X11 or Wayland session (currently the GNOME Shell and wlroots-based Wayland compositors are supported).

Arch Linux and derivatives:

An up to date build can be installed from the AUR.

To try it out, simply create a configuration file and start it using:

systemctl start keymapperd
keymapper

The package already adds keymapper to the desktop environment's auto-started applications. As long as the service is not running, it does nothing but wait for the service to start. So to install permanently, only the keymapperd service has to be enabled:

systemctl enable keymapperd

Other Linux distributions:

No packages are provided yet, please follow the instructions for building manually or download a portable build from the latest release page.

To try it out, simply create a configuration file and start it using:

sudo ./keymapperd &
./keymapper

Windows

A portable build can be downloaded from the latest release page.

keymapper.exe can simply be started without special permissions. To install it permanently, simply add it to the auto-started applications.

There are two modes of operation:

  • By default a Low level keyboard hook is used, which generally works fine but has a few limitations. Foremost the Windows key cannot be mapped reliably and applications which are running as administrator (like the login screen, task manager, ...) resist any mapping.

  • When the command line argument -i is passed, the Interception library is used. It does not have these limitations, but a special keyboard driver needs to be installed and the interception.dll needs to be placed in the working directory.

Building

A C++17 conforming compiler is required. A script for the CMake build system is provided.

Installing dependencies on Debian Linux and derivatives:

sudo apt install build-essential git cmake libudev-dev libusb-1.0-0-dev libx11-dev libdbus-1-dev libwayland-dev

Checking out the source:

git clone https://github.com/houmain/keymapper

Building:

cd keymapper
cmake -B build
cmake --build build

License

It is released under the GNU GPLv3. It comes with absolutely no warranty. Please see LICENSE for license details.

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