After using Windows for some time I've got accustomed to having weird vim-like hotkeys using AutoHotkey.
I've not found a satisfactory solution for Linux until I stumbed across kbd-mangler.
kbd-mangler
gives low-level access to keyboard and mouse events, so I am trying to use this to create an AHK-like experience, or at least recover my keybindings.
The problem with kbd-mangler is that it is from 2010 and thus quite old. It depends on mozillas's js library libmozjs
which has been deprecated long ago.
However, one can get the required c library from older releases of xul-runner
.
In 2010, they didn't build xul-runner
for x64 when doing stable releases, but they did on nightlies!
So here is a guide on how to build kbd-mangler
and get going with writing your own system-wide hotkeys!
NOTE: I did not write most of this code myself; this is just a small repackaging and updated guide to use the software written by Gena Batyan to whom all credit is due!
git clone
this repository down.- download the appropriate version of xulrunner from here (remember to download the sdk version)
- extract the zip archive you just downloaded to wherever you'd like: I've used
opt/xulrunner-sdk-1.9.2.1pre
- modify the
Makefile
to makeLDFLAGS
andCFLAGS
point to the location of the xulrunner sdk. - run
make
in the repo directory kbd-mangler
should be built successfully!- inspect
run.sh
and follow the instructions in there to find your keyboard device file- remember to edit the
export LD_LIBRARY_PATH
line as to point to your xulrunner sdk folder (same as forLDFLAGS
)
- remember to edit the
- use
sudo ./run.sh [YOUR_SCRIPT_FILE]
to make the magic appear! - in
adam/
andexamples/
there are some inspirational scripts -- specifically theadam/ahk.js
file is what I personally use.
Since run.sh
will need to be run with sudo
, you need to allow your user to run it as root with no password.
On Ubuntu/Debian you can do this by appending the following line to visudo
or a file in /etc/sudoers.d
:
[your_user] ALL = (root) NOPASSWD: [path_to_run_sh]
Where [your_user]
and [path_to_run_sh]
should be substituted with your username and the path to run.sh
respectively.
Now you can add a line to .xprofile
or something similar to start run.sh
on login
sudo [path_to_run_sh] [path_to_your_js_script]
See the documentation for kbd-mangler for more information (can also be found in the docs
folder).
- Why this compared to e.g. autokey? Many other solutions may not require
sudo
privileges, but capture key input on a higher level using e.g. X. This is a problem for applications that do not use this framework. For example, thekitty
terminal does not respect autokey's configuration. Using kbd-mangler, we don't have this problem. On the other hand, it must be run as root. - Why javascript? kbd-mangler uses javascript and I've not had time to port it to something else.
- Why such an old version of js? See answer above :). Pull requests are welcome!