This is an old revision of the document!
KeyMapper is an app that can remap keys in extremely customizable ways.
A key map can be set to rebind a key completely, or to keep a key function while adding additional functionality. You can have have functions bound to single press, double press, and long press. You can also chain these key inputs to create sequenced macros.
For example, using Key Mapper you can bind keys to turn up and down volume, or turn up and down brightness.
Key Mapper also has grouping for keybinds, which you can assign to app constraints to create app specific profiles. For example, binding a key to tap a screen element such as the send button in a messaging app.
Installation
Key Mapper can be installed from F-Droid: https://f-droid.org/packages/io.github.sds100.keymapper/
Usage
If you want to have Key Mapper bind buttons to keyboard inputs use key codes (Requires Shuzuku/Sui)[https://github.com/RikkaApps/Sui].
Note: Unfortunately Key Mapper does not work while the phone is closed, as the phone enters a kind of sleep mode.