Linux でキーボード入力の効率化を図る その3 xdotool + xbindkeys 断念編
前回は Linux でホームポジションキーパーに近いことをするために xdotool + xbindkeys を使うと決めました。
xdotool は Linux Mint 19.1 Cinnamon に標準でインストールされているので、xbindkeys をインストールして使ってみます。
xbindkeys のインストール
「ソフトウェアの管理」からインストールできました。
ターミナルからやるなら
sudo apt install xbindkeys
ですね。
xbindkeys でキーコードを取得
xbindkeys でキーコードを取得するにはターミナルで以下のコマンドを実行します。
xbindkeys -k
おっと、エラーが出ました。
「ホームディレクトリに設定ファイル .xbindkeysrc が無いよ。」と言われているようです。
空の .xbindkeysrc を作ってもいいのですが、今回は xbindkeys の機能でサンプルファイルを出力してみます。
.xbindkeysrc のサンプルファイル
.xbindkeysrc のサンプルファイルを作成するには以下のコマンドを実行します。
xbindkeys -d > ~/.xbindkeysrc
「> ~/.xbindkeysrc」をつけずに
xbindkeys -d
だと設定ファイルの内容がターミナルに表示されるだけで、.xbindkeysrc は作成されませんでした。
作成された設定ファイルの中身はこんな感じです。
# For the benefit of emacs users: -*- shell-script -*- ########################### # xbindkeys configuration # ########################### # # Version: 1.8.6 # # If you edit this file, do not forget to uncomment any lines # that you change. # The pound(#) symbol may be used anywhere for comments. # # To specify a key, you can use 'xbindkeys --key' or # 'xbindkeys --multikey' and put one of the two lines in this file. # # The format of a command line is: # "command to start" # associated key # # # A list of keys is in /usr/include/X11/keysym.h and in # /usr/include/X11/keysymdef.h # The XK_ is not needed. # # List of modifier: # Release, Control, Shift, Mod1 (Alt), Mod2 (NumLock), # Mod3 (CapsLock), Mod4, Mod5 (Scroll). # # The release modifier is not a standard X modifier, but you can # use it if you want to catch release events instead of press events # By defaults, xbindkeys does not pay attention with the modifiers # NumLock, CapsLock and ScrollLock. # Uncomment the lines above if you want to pay attention to them. #keystate_numlock = enable #keystate_capslock = enable #keystate_scrolllock= enable # Examples of commands: "xbindkeys_show" control+shift + q # set directly keycode (here control + f with my keyboard) #"xterm" # c:41 + m:0x4 # specify a mouse button #"xterm" # control + b:2 #"xterm -geom 50x20+20+20" # Shift+Mod2+alt + s # ## set directly keycode (here control+alt+mod2 + f with my keyboard) #"xterm" # alt + c:0x29 + m:4 + mod2 # ## Control+Shift+a release event starts rxvt #"rxvt" # release+control+shift + a # ## Control + mouse button 2 release event starts rxvt #"rxvt" # Control + b:2 + Release ################################## # End of xbindkeys configuration # ##################################
ほとんどが「#」でコメントアウトされてますね😀
xbindkeys でキーコードを取得 リトライ
ターミナルで以下のコマンドを実行、と。
xbindkeys -k
ウィンドウがでてきたらキー入力。試しにスペースキーを押してみると。。。
"(Scheme function)" m:0x10 + c:65 Mod2 + space
そのまんま「space」でしたね。
「Mod2」というのは NumLock が ON の状態を表します。デフォルトでは付けても付けなくても同じ動作になります。
設定ファイルを書いてみる
space + g でスペースを出してほしいので、.xbindkeysrc に以下のように書きました。
"xdotool key space" space + g
xbindkeys を下記のコマンドで再起動して設定を反映し、
killall xbindkeys; xbindkeys
space と g を同時押ししてみると。。。
動きませんでした😭
どうやら修飾キーとして使えるのはサンプルファイル内の「List of modifier」に列挙されているものだけのようです。
.xbindkeysrc に直接 xdotool のコマンドを書くのも NG のようで、sh ファイルに書いてやる必要があるみたいです。
参考:xbindkeysで捗るお話 - ぺんぎんさんのめもちょう
スペースキーを修飾キーとして利用できない以上、ホームポジションキーパーに近いことをするのは不可能だと分かりました。残念。