Carabiner for Linux?

Background : For the past five years I have been using Mac hardware (most MacBook Pro laptops for the most part) and software after many years of using Gnu / Linux on a regular PC with ergonomic keyboards. More importantly, as a heavy Emacs user, switching to a Mac was painful, and Apple's standard short keyboard was crazy and inevitable. I prevented RSI using the Karabiner tool for making two small but very important changes: 1) changing the “cap” key to generate the menu key (f13) when pressed alone, and the key code with the control key when pressing another key; 2) change the return key in the same way, get a return when pressed alone and the key of the key with the changed key when pressed with another key. Frustrated by recent Apple hardware and software solutions, I am now returning to Gnu / Linux (Ubuntu, if that matters), but sticks with Mac laptops.

Question : since Karabiner is an OS X-only tool that does not have an available Gnu / Linux counterpart, it seems I will have to write and / or modify some code to get the caplock key and return. Carabiner allows for double behavior. Karabiner writes that xbindkeys and rbindkeys perform key remapping, but at first glance they don't seem to handle the behavior of the dual function. Now I am struggling with porting the Carabiner or creating a whole new tool. And, of course, there may be other approaches. So my question is: what programming tips would you offer to solve this problem? Especially one that can be developed in hours, days, or weeks, and not in months.

Notes

1) There are various approaches related to behavioral changes, such as switching control and command keys. Many of them were tested with varying degrees of satisfaction. The parallel approach of Karabiner is IMHO, far and far, the most effective in that it provides the symmetry of the control key on the keyboard home line and for all applications!

2) Other equipment may also be offered. I tried Dell, HP, Lenovo, Acer computers and looked a lot more. None of them are comparable to the combined power, size, feel and style of the best Apple products, albeit at a high price. For example, the Dell Precision 7510 is bulky and has a trackpad that looks like sandpaper; Lenovo X1 (a very good system) does not have a Thunderbolt port; and etc.

3) External keyboards are also not a starter because of the requirements for a laptop; an external keyboard does not occur on an airplane or train.

+17
source share
1 answer

You can achieve this on TTY , Wayland, and X11 using Interception Tools , which interacts directly with libevdev and libudev.

Install the Interception Tools and a plugin such as caps2esc or interception-k2k . Then you need to configure the hook to use the plugin. For caps2esc, you can use the following /etc/udevmon.yaml file:

 - JOB: "intercept -g $DEVNODE | caps2esc | uinput -d $DEVNODE" DEVICE: EVENTS: EV_KEY: [KEY_CAPSLOCK, KEY_ESC] 

Then run it as root:

nice -n -20 /usr/bin/udevmon -c /etc/udevmon.yaml

You need to make sure it starts when you log in . For systemd, you can use the following service:

 [Unit] Description=udevmon [Service] ExecStart=/usr/bin/nice -n -20 /usr/bin/udevmon -c /etc/udevmon.yaml [Install] WantedBy=multi-user.target 

For X11 only, you can use setxkbmap and xcape .

First change the Caps Lock so that it acts as a Ctrl modifier:

setxkbmap -option caps:ctrl_modifier

Then set Caps Lock as the Menu key if it is pressed less than the timeout (500 ms by default):

xcape -e 'Caps_Lock=Menu'

xcape works like a daemon, so you need to make sure it starts when you log in . setxkbmap sets the keyboard layout only for the current X session, you can install it permanently in the xinitrc, xprofile or X configuration files.

Postscript For those who want to use an external keyboard, the open source Ultimate Hacking Keyboard (UHK) allows you to use this feature.

+1
source

Source: https://habr.com/ru/post/1013576/


All Articles