過去に
のように試行錯誤したがChromeのアドレスバー上などで作用しなかったので最終的にxkeysnailで実現した。
github.com
実現方法
README.md通りにインストールしていく。
$ sudo apt install python3-pip
$ sudo pip3 install xkeysnail
sudo権限が必要。
設定ファイルとして、 config.py
を任意の場所に作成する。
xkeysnail/config.py at master · mooz/xkeysnail · GitHub を参考にすればよい。
まずは適用されることを確認したかったので、一旦シンプルな内容にした。
# -*- coding: utf-8 -*-
from xkeysnail.transform import *
# define timeout for multipurpose_modmap
define_timeout(1)
define_keymap(None, {
# Ctrl+h to backspace
K("C-h"): (K("backspace")),
})
起動
$ sudo xkeysnail config.py
とすれば起動するらしいのだが、 Xlib.error.DisplayConnectionError
というエラーが出て起動に失敗した。
python - How to fix error Xlib.error.DisplayConnectionError: Can't connect to display ":0": b'No protocol specified\n' - Stack Overflow によると、 xhost +
を叩けばよいらしい。
$ xhost +
$ sudo xkeysnail config.py
██╗ ██╗██╗ ██╗███████╗██╗ ██╗
╚██╗██╔╝██║ ██╔╝██╔════╝╚██╗ ██╔╝
╚███╔╝ █████╔╝ █████╗ ╚████╔╝
██╔██╗ ██╔═██╗ ██╔══╝ ╚██╔╝
██╔╝ ██╗██║ ██╗███████╗ ██║
╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝ ╚═╝
███████╗███╗ ██╗ █████╗ ██╗██╗
██╔════╝████╗ ██║██╔══██╗██║██║
███████╗██╔██╗ ██║███████║██║██║
╚════██║██║╚██╗██║██╔══██║██║██║
███████║██║ ╚████║██║ ██║██║███████╗
╚══════╝╚═╝ ╚═══╝╚═╝ ╚═╝╚═╝╚══════╝
v0.4.0
No keyboard devices specified via (--devices) option.
xkeysnail picks up keyboard-ish devices from the list below:
------------------------------------------------------------------------------------------------------
Device Name Phys
------------------------------------------------------------------------------------------------------
/dev/input/event0 Power Button PNP0C0C/button/input0
/dev/input/event1 Power Button LNXPWRBN/button/input0
/dev/input/event2 MSI MYSTIC LIGHT usb-0000:2a:00.3-5/input0
/dev/input/event3 ZSA Moonlander Mark I usb-0000:2f:00.3-1/input0
...
Okay, now enable remapping on the following device(s):
できた。
$HOMEに.xprofileを作成し、こんな感じに書いた。
if [ -x /usr/local/bin/xkeysnail ]; then
xhost +
sudo /usr/local/bin/xkeysnail /home/shinespark/git/dotfiles/ubuntu/xkeysnail/config.py &
fi
再起動したら、至る所でCtrl+hでbackspaceできるようになったことを確認。最高。
自動起動(systemd)
Suspend状態から復帰した時などに効かなくなっていたので、安定性も鑑みてsystemd化した。
/etc/systemd/system/xkeysnails.service
に以下のファイルを配置。
[Unit]
Description=Service for xkeysnail
[Service]
Environment=DISPLAY=:0
ExecStart=/usr/local/bin/xkeysnail /home/shinespark/git/dotfiles/ubuntu/xkeysnail/config.py
StandardOutput=null
Restart=always
Type=simple
RestartSec=10
[Install]
WantedBy=graphical.target
.xprofile
は下記のように書き換え
if [ -x /usr/local/bin/xkeysnail ]; then
xhost +SI:localuser:root
fi
サービスを読み込み & 自動起動を有効にする。
sudo systemctl daemon-reload
sudo systemctl enable xkeysnail
後は再起動後に active になっていればOK.
$ sudo systemctl status xkeysnail
● xkeysnail.service - Service for xkeysnail
Loaded: loaded (/etc/systemd/system/xkeysnail.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2021-12-17 16:24:22 JST; 5min ago
Main PID: 9060 (xkeysnail)
Tasks: 1 (limit: 77014)
Memory: 14.6M
CGroup: /system.slice/xkeysnail.service
└─9060 /usr/bin/python3 /usr/local/bin/xkeysnail /home/shinespark/git/dotfiles/ubuntu/xkeysnail/config.py
12月 17 16:24:22 Linux-Mint systemd[1]: Started Service for xkeysnail.
参考