A small tool that applies Emacs-keybindings on all Linux/X11 applications is provided here. By using this, you can use any applications (e.g., LibreOffice, okular (PDF viewer), and etc.) with Emacs-like keybindings running on Linux
This tool is implemented as a proof-of-concept of an alternative of XKeymacs or emacs.ahk, which are implemented on Win32 and thus lacked on Linux/X11. It is made up of about 1,000 lines of code, and thus relatively easy to hack. (I personally hope that someone builds a more practical and generalized keybinding configuration tool using similar techniques :-)
Simple do "make & make install", and the executable file (x11keymacs) will be installed under /usr/local/bin
$ cd x11keymacs/
$ make
$ sudo make install
In order to run x11keymacs, you need the following previleges:
By running the following command from the user having the above privileges, keyboard input is converted to Windows-like input from the original Emacs-like keybindings.
(Note that you need to modify the /dev/input/... part to match your keyboard model.)
$ /usr/local/bin/x11keymacs /dev/input/by-id/usb-PFU_Limited_HHKB_Professional_JP-event-kbd &
For instance, Ctrl-P key input is converted to up key, which helps Emacs-users to avoid being frustrated under some "Print" dialog box that has mistakenly popped up.
X11keymacs accepts --exclude filename
option for excluding window titles from applying keyboard input conversion using regular expressions. For example, by adding --exclude $HOME/.x11keymacs_exclude
to the parameter and by providing the "$HOME/.x11keymacs_exclude" of the following content would exclude Emacs(Gtk+) and VMware Player from the keyboard input conversion targets.
^emacs-gtk@
(^|- )VMware Player$
In my case, I've personally configured to launch this tool on X-server startup. Here's how I have done this:
takeshi ALL=(ALL) ALL, SETENV:NOPASSWD:/usr/local/bin/x11keymacs
$HOME/.xinitrc
to execute x11keymacs
cp $HOME/.xinitrc.template $HOME/.xinitrc
first, and add the following lines to .xinitrc:
#
# Add your own lines here...
#
if test -e $HOME/.x11keymacs_excludes; then
xhost +
sudo -b DISPLAY="$DISPLAY" /usr/local/bin/x11keymacs \
--exclude $HOME/.x11keymacs_excludes \
/dev/input/by-id/usb-PFU_Limited_HHKB_Professional_JP-event-kbd
fi
The above settings works for me, at least to a level that I can daily use it for my work :-)
diff --git a/emacs.cpp b/emacs.cpp
index 7e17802..d32bdca 100644
--- a/emacs.cpp
+++ b/emacs.cpp
@@ -73,7 +73,7 @@ void EmacsConverter::typeKey(__u16 code, int metaKeys)
BIT_LEFTALT, BIT_RIGHTALT,
};
static const __u16 keys[] = {
- KEY_LEFTCTRL, KEY_RIGHTCTRL,
+ KEY_CAPSLOCK, KEY_RIGHTCTRL,
KEY_LEFTSHIFT, KEY_RIGHTSHIFT,
KEY_LEFTALT, KEY_RIGHTALT,
};
@@ -139,7 +139,7 @@ void EmacsConverter::typeKey(__u16 code, int metaKeys)
bool EmacsConverter::handleKeyInput(struct input_event* input)
{
switch (input->code) {
- case KEY_LEFTCTRL:
+ case KEY_CAPSLOCK:
return handleMetaKeyInput(input, BIT_LEFTCTRL);
case KEY_RIGHTCTRL:
return handleMetaKeyInput(input, BIT_RIGHTCTRL);
(TO BE TRANSLATED)
[ Back ]
Yashiro Takeshi <yashiromann@gmail.com>