LoginSignup
1
0

More than 3 years have passed since last update.

Ubuntu Linuxで、Tabをqにする

Last updated at Posted at 2020-04-01

TL;DR

  • やんごとなき理由で、Tabキーをqキーにしたい
  • 対象はUbuntu Linux
  • xevでキーコードとkeysymを調べてxmodmapで割り当てる

環境

$ uname -srvmpio
Linux 4.18.0-25-generic #26~18.04.1-Ubuntu SMP Thu Jun 27 07:28:31 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux


$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.4 LTS
Release:    18.04
Codename:   bionic

xmodmapxev

xmodmapというコマンドで、キーの割り当てを変更できます。

$ xmodmap -e "keycode [keycode] = [keysym]"

[keycode]が指す物理的なキーを、[keysym]が指す内容に割り当てることができます。

これらを調べるには、xevコマンドを使います。

$ xev

コマンド起動後にキーを押すと、キーコードとkeysymを調べることができます。

"q"を押した場合は、keycodeは24で、keysymはqです。

KeyPress event, serial 37, synthetic NO, window 0x5e00001,
    root 0x17e, subw 0x0, time 5825075, (42,674), root:(197,823),
    state 0x0, keycode 24 (keysym 0x71, q), same_screen YES,
    XLookupString gives 1 bytes: (71) "q"
    XmbLookupString gives 1 bytes: (71) "q"
    XFilterEvent returns: False

"Tab"を押した場合は、keycodeは23で、keysymはTabです。

KeyPress event, serial 37, synthetic NO, window 0x5e00001,
    root 0x17e, subw 0x0, time 5804891, (141,203), root:(296,352),
    state 0x0, keycode 23 (keysym 0xff09, Tab), same_screen YES,
    XLookupString gives 1 bytes: (09) " "
    XmbLookupString gives 1 bytes: (09) "   "
    XFilterEvent returns: False

Tabをqにする

ここまでの情報が得られたので、Tabをqにするには、以下のようにします。

$ xmodmap -e "keycode 23 = q"

元に戻すには、以下のようにします。

$ xmodmap -e "keycode 23 = Tab"

なお、この変更は現在のX Windowセッションのみで、永続的な適用は行われません。

個人的には、それで問題ないので…。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0