ubuntu上のキーボード¥と\の挙動

 iBus-mozcでの¥と\を押した時の挙動。

¥ (BackSpaceの左)

  • IMEオン状態でも¥が直接入力される。
  • 未確定文字列があっても、アプリ側のカーソル位置に¥が直接入力される。確定後戻って削除する必要がある。

\ (右シフトの左)

  • IMEオフ状態だと\
  • IMEオン状態だと未確定の\となり、変換候補に半角全角の¥/の4つが表示される。


困っていること、改善したい方向

 BSを叩こうとして¥を叩くことが時々あるので、¥を無効化したい。ただし|を使うことがあるのでキー全体を無効化するのはあかん。
 せめて¥が未確定状態で入力されたらBSを叩き直すだけで削除できるのに。
 ローマ字変換テーブルに¥を¥で登録してあるけど、変化なし。
 いつからこうなったのかは記憶が定かではないけど、phpでの挙動が変わったのと一致しているかもしれない。¥と\って今どうなっとるんかなと思って検索してみたらこんな感じ。もしかしてキーボードのUnicode対応が上記の時(21.10)に行われたんかも。
penpen-dev.com
 xevしてみた。BSの隣の¥では

KeyPress event, serial 37, synthetic NO, window 0x3800001,
root 0x9b4, subw 0x0, time 14850776, (810,83), root:(1681,526),
state 0x10, keycode 132 (keysym 0xa5, yen), same_screen YES,
XLookupString gives 2 bytes: (c2 a5) "¥"
XmbLookupString gives 2 bytes: (c2 a5) "¥"
XFilterEvent returns: False

KeyPress event, serial 37, synthetic NO, window 0x3800001,
root 0x9b4, subw 0x0, time 14851486, (810,83), root:(1681,526),
state 0x10, keycode 50 (keysym 0xffe1, Shift_L), same_screen YES,
XLookupString gives 0 bytes:
XmbLookupString gives 0 bytes:
XFilterEvent returns: False

KeyPress event, serial 37, synthetic NO, window 0x3800001,
root 0x9b4, subw 0x0, time 14851838, (810,83), root:(1681,526),
state 0x11, keycode 132 (keysym 0x7c, bar), same_screen YES,
XLookupString gives 1 bytes: (7c) "|"
XmbLookupString gives 1 bytes: (7c) "|"
XFilterEvent returns: False

 右shiftの隣の\では

KeyPress event, serial 37, synthetic NO, window 0x3800001,
root 0x9b4, subw 0x0, time 14998476, (78,268), root:(949,711),
state 0x10, keycode 97 (keysym 0x5c, backslash), same_screen YES,
XLookupString gives 1 bytes: (5c) "\"
XmbLookupString gives 1 bytes: (5c) "\"
XFilterEvent returns: False

KeyPress event, serial 37, synthetic NO, window 0x3800001,
root 0x9b4, subw 0x0, time 14999700, (78,268), root:(949,711),
state 0x10, keycode 50 (keysym 0xffe1, Shift_L), same_screen YES,
XLookupString gives 0 bytes:
XmbLookupString gives 0 bytes:
XFilterEvent returns: False

KeyPress event, serial 37, synthetic NO, window 0x3800001,
root 0x9b4, subw 0x0, time 14999948, (78,268), root:(949,711),
state 0x11, keycode 97 (keysym 0x5f, underscore), same_screen YES,
XLookupString gives 1 bytes: (5f) "_"
XmbLookupString gives 1 bytes: (5f) "_"
XFilterEvent returns: Fals

 キーのシフトなし状態のコード書き換えは

xmodmap -e 'keycode 132 = bar'

 とすれば可能。シフトキーありの場合はどうすればいいの?と思ってたら第2引数に指定すればいいらしい。
wiki.archlinux.jp

xmodmap -e 'keycode 132 = bar yen'

 これで¥を|に、shift+¥を¥に割り当てることはできた。あとは.xmodmapに書き込んで起動時に実行させればいいということに。他のキー変更同様/etc/default/keyboardに書き込めれば1箇所だけですむんやけど。

 ふと気がついたけど、BSと押し間違えるならBSにしてしまったらええんちゃうの。.xmodmapを以下のように変更。¥が必要な時はIME経由で。

!BS横のキーをBSに
keycode 132 = BackSpace bar