全てのマウスボタンを動作させる

提供: ArchWiki
ナビゲーションに移動 検索に移動

関連記事

この記事では4つ以上のマウスボタンが付いているマウスを使っているユーザーに全てのボタンを使用する方法を説明します。そうしたマウスは Logitech (Logitech Marble® Mouse) や Microsoft などが製作しています。

Prerequisite testing mouse input in X

This page assumes you are using Xorg (X Window System) and not Wayland.

You will first want to check what X sees from your mouse. X events can be displayed by the xev utility. A window will pop up by running

$ xev -event button | grep button

Any xevents (like moving, resizing, or clicking in) that window will then be reported to the console you launched xev from. Since you are filtering for lines which contain "button" it will show mouse click and release events with their relevant button numbers. For most mice, this will be '1' for left button, '2' for middle, '3' for right. Other buttons will vary (e.g. for an Logitech MX Master 3 the scroll wheel is 4 & 5, thumb wheel is 6 & 7, the thumb-tip button is 9, and the inner-thumb button is 8).

Example output:

state 0x0, button 1, same_screen YES
state 0x100, button 1, same_screen YES
state 0x0, button 9, same_screen YES
state 0x0, button 9, same_screen YES

This corresponds to a left mouse click and release followed by a thumb-tip click and release.

You can use xev to confirm your mouse button numbers and to confirm that X is being notified of mouse clicks.

Rebinding mouse and keyboard functions

This section covers details of using various tools to rearrange mouse and keyboard functions.

Binding mouse buttons to keyboard functions

xte

この記事あるいはセクションで使われている用語や表現には問題が存在します。
議論: Duplicates xbindkeys, assumes xte instead of linking Xorg#Automation. (議論: トーク:全てのマウスボタンを動作させる#)

xte from xautomation comes handy when we want to bind keyboard buttons to mouse.

Here is example ~/.xbindkeysrc which binds Shift_R to mouse button 3 ("right click"):

~/.xbindkeysrc
"xte 'mouseclick 3'"
  Shift_R

Binding keyboard keys to mouse buttons

xvkbd and xbindkeys

この記事あるいはセクションで使われている用語や表現には問題が存在します。
議論: Duplicates xbindkeys, assumes xvkbd instead of linking Xorg#Automation. (議論: トーク:全てのマウスボタンを動作させる#)

Let us say we want to bind some mouse buttons to keyboard ones. The problem we will encounter is that we do not know how to emulate a key press. Here comes in handy xvkbdAUR. We can use it along with xbindkeys.

$ xbindkeys --defaults >> ~/.xbindkeysrc
$ xbindkeys

To restart xbindkeys type:

$ pkill -f xbindkeys
$ xbindkeys 

Here is example ~/.xbindkeysrc config:

"xvkbd  -text "\[F8]""
       m:0x0 + b:8
"xvkbd  -text "\[Shift]\[Left]""
       m:0x0 + b:9
"xvkbd  -text "\[Shift]\[Right]""
       m:0x0 + b:10
"xvkbd  -text 2"
       m:0x0 + b:11
"xvkbd  -text 3"
       m:0x0 + b:12

If you want to check your mouse buttons number use xev. Do not forget to type capital letters in xvkbd -text usage and to escape opening bracket with \ or you get simply [Shift] written.

Here is an example for xbindkeys to enable x selection paste(third click pasting), you need both xsel and xvkbd installed, What it does it executes that command whenever button 13 of the mouse is pressed (in ~/.xbindkeysrc) :

"xvkbd -no-jump-pointer -text "\D1$(xsel)" 2>/dev/null"
b:13

This is an example for a keybinding for Meta+M:

"xvkbd  -text "\{+Super_L}m\{-Super_L}""
b:10

evrouter

この記事またはセクションは加筆を必要としています。
理由: What "different methods of reading input"? (議論: トーク:全てのマウスボタンを動作させる#)

Some programs, especially games, use different methods of reading input, so another program is needed: evrouterAUR.

For the evrouter command to be able to read the input devices, it will have to be run in the input group (or as root). This can be achieved by adding yourself to that group:

# gpasswd -a user input

Now we can use the --dump option to display what the button to be changed is called:

ヒント: For USB devices udev will usually create symbolic links in /dev/input/by-id/ which can be used to refer to specific devices.
$ evrouter --dump /dev/input/event*
device  0: /dev/input/event0: AT Translated Set 2 keyboard
device  1: /dev/input/event1: Microsoft Microsoft Trackball Explorer®
device  2: /dev/input/event2: Sleep Button
device  3: /dev/input/event3: Power Button
device  4: /dev/input/event4: Power Button
device  5: /dev/input/event5: PC Speaker
Display name: :0.0

Now press the buttons that you wish to change:

Window "(null)": # Window title
# Window "(null)": # Resource name
# Window "(null)": # Class name
"Microsoft Trackball Explorer®" "/dev/input/event1" none key/275 "fill this in!"

Window "(null)": # Window title
# Window "(null)": # Resource name
# Window "(null)": # Class name
"Microsoft Trackball Explorer®" "/dev/input/event1" none key/276 "fill this in!"

The line that ends with "fill this in!" can be copied into the configuration file which by default is ~/.evrouterrc. For example, using the X11 key event emulator built into evrouter:

~/.evrouterrc
"Microsoft Trackball Explorer®" "/dev/input/event*" any key/275 "XKey/1"
"Microsoft Trackball Explorer®" "/dev/input/event*" any key/276 "XKey/2"

The 'event1' was changed to 'event*' in case udev gives it a different device number at boot. The 'none' was changed to 'any' so that the rule works even if any modifier keys are pressed when the button is pressed. To determine the key codes (in brackets) you can use

# xmodmap -pk

See evrouter(1) for a full explanation of the fields.

ヒント: Rules can apply only to specific windows, see evrouter(1) for details.

After setting up the configuration file, run it as a daemon:

$ evrouter /dev/input/event*

To stop the daemon:

$ evrouter -q
$ rm -f /tmp/.evrouter*
ノート: evrouter will fail to start if the /tmp/.evrouter:0.0 file exists but does not delete it when exiting, so you will have to delete it yourself.

ユーザーツール

imwheel でマウスの回転やボタンのマッピングを設定することができます。システム全体で設定したり、あるいは個別のプロセスごとに設定できます。

全てのアプリケーションで前に戻る・先に進むのボタンを有効にして Chromium でスクロール速度を上げる ~/.imwheelrc の例:

"^chromium$"
None, Up, Button4, 3
None, Down, Button5, 3
".*" None, Thumb1, Alt_L|Left None, Thumb2, Alt_L|Right

また、公式リポジトリにある Logitech MX 用のツールである lomocoAUR は解像度を設定したり、スマートスクロールを有効化・無効化したりできます。

/etc/udev/lomoco_mouse.conf を開いて、マウスが udev によってロードされたときに自動的に適用したいオプションを設定してください。

ノート: The lomoco package may be out of date. There is a hack for newer Logitech mice: [1]

evdev Xorg.conf のセットアップ

マウスの名前を確認

ノート: 正確な情報を得るために、Xorg やマウスのドライバーをロードする前にコマンドを実行する必要がある場合もあります。

まず最初にマウスの名前を確認します。次のコマンドを実行してください:

$ egrep "Name|Handlers" /proc/bus/input/devices | egrep -B1 'Handlers.*mouse'

以下のような出力がされます:

N: Name="Logitech USB Gaming Mouse"
H: Handlers=mouse0 event0 ts0 

もしくはマウスが複数ある場合:

N: Name="Kensington Kensington Expert Mouse Wireless"
H: Handlers=event0 mouse0 
--
N: Name="Logitech USB Receiver"
H: Handlers=kbd event2 mouse1

Handlers=mouse0 というのがマウスであり、デバイスの名前は Logitech USB Gaming Mouse です。名前はマウスによって異なります。

デバイスの名前をコピーしたら、/etc/X11/xorg.conf を開いて下さい。

Xorg の設定

X がマウスを使う方法を設定するため xorg.conf にエントリを記述します。エントリは以下のようになります:

Section "InputDevice"
  Identifier      "Evdev Mouse"
  Driver          "evdev"
  Option          "Name" "Logitech USB Gaming Mouse"
  Option          "evBits"  "+1-2"
  Option          "keyBits" "~272-287"
  Option          "relBits" "~0-2 ~6 ~8"
  Option          "Pass"    "3"
  Option          "CorePointer"
EndSection

Name オプションは先にコピーした名前に置き換えて下さい。マウスを複数使う場合や Xorg をロードしたときにエラーが発生する場合は CorePointer オプションは外して下さい。他のオプションはどれも evdev の基本的なマウス設定で、ほとんどのマウスで機能します。

次に、マウスを使うように X を設定します。xorg.confServerLayout を見て下さい。

ServerLayout セクションを修正してデバイスとして "Evdev Mouse" を使うようにしてください。設定したら、以下のようになります:

Section "ServerLayout"
  Identifier     "Default Layout"
  Screen 0       "Monitor0" 0 0
  InputDevice    "Keyboard0" "CoreKeyboard"
  InputDevice    "Evdev Mouse" "CorePointer"
EndSection

レイアウトで変更する必要があるのは (マウスを示す) InputDevice 行だけです。

Logitech G5 マウスを使っていてマウスが動作しない場合、InputDevice セクションに以下を記述してみてください ([#] は egrep 'Name|Handlers' /proc/bus/input/devices で確認できる数字に置き換えて下さい)。必要ない場合は、記述しないでください。

Option "Device" "/dev/input/event[#]"

上記の方法で、再起動後にマウスが動作しなくなる場合、/dev/input/by-id にシンボリックリンクを作成してみてください。例:

Option      "Device" "/dev/input/by-id/usb-Logitech_USB_Receiver-event-mouse"

適当な ID は、次を実行することで確認できます:

$ ls /dev/input/by-id/

evdev Xorg.conf 設定後

Google Chrome

動作します。横スクロールは何も設定しなくても動作します。スクロールホイールを左右に押して下さい。親指ボタンで次/前のページに移動します。

Opera

動作します。ボタンのマッピングは Preferences > Advanced > Shortcuts > Mouse set-up で簡単に変えられます。例えば、button 8back にバインドするには:

  1. マウスの設定から Application ドロップダウンを開く
  2. インプットカラムに、次を入力: Button 8
  3. アクションカラムに、次を入力: Back

Firefox

横スクロール

左と右のスクロールの代わりに、戻ると進むを有効にするには、about:config で以下の設定を変更します:

mousewheel.default.action.override_x         2
mousewheel.default.delta_multiplier_x       -100

親指ボタン - 進むと戻る

ノート: The following maybe redundant depending on whether xev detects all your mouse buttons correctly (functions can be mapped on a per-app basis) or you want to change the default behaviour.

キーストロークを適当なマウスボタンにマッピングして xvkbdAURxbindkeys をインストールする必要があります。

戻る/進むを使用する最近のアプリケーションでは、デフォルトで XF86Back が戻るに、XF86Forward が進むにマッピングされています。ほとんどの MX マウスでは親指ボタンは 8 や 9 と認識されます。使用しているボタンで番号が異なっている場合、xev を使ってボタンの番号を確認して例で使われている番号を置き換えて下さい (b:8 & b:9)。

MX マウスを使っている場合、以下の内容で ~/.xbindkeysrc ファイルを作成します:

# Mouse Buttons
"xvkbd -xsendevent -text "\[XF86Back]""
m:0x0 + b:8 
"xvkbd -xsendevent -text "\[XF86Forward]""
m:0x0 + b:9

次にテストです。以下のコマンドを実行してください。問題ないようでしたら xbindkeys を .xinitrc など (X が起動するたびに読み込まれるファイル) に追加してください。また、Epiphany や Konqueror では特別な設定をしたり Imwheel を使用しなくとも機能します。

xbindkeys

詳しい情報は Logitech MX1000 にあります。

xmodmap の調整

ノート: None of the below is necessary with evdev, but it's here for non-evdev users. Unless something does not work on your mouse, ignore this whole section!

.xinitrc を使って X をロードしている場合、以下を .xinitrc に追加してください (ボタンの数字は必要に応じて変更してください):

xmodmap -e "pointer = 1 2 3 6 7 8 9 10 11 12 4 5" &

ボタン 4 と 5 は一番最後に置いて下さい。そうしないとスクロールホイールが動作しません。

.xinitrc ではなく GDM/XDM/KDM を使っている場合、~/.Xmodmap ファイルを作成して以下を追加します (ボタンの数字は必要に応じて変更してください):

pointer = 1 2 3 6 7 8 9 10 11 12 4 5
  • GDM/XDM/KDM は ~/.Xmodmap ファイルが存在すると読み込みますが、startx は読み込みません。~/.xinitrc に次のコマンドを追加して読み込ませることもできます: xmodmap ~/.Xmodmap。何か変更が必要になったときに *DM と startx のどちらを使っている場合でも ~/.Xmodmap を編集すれば良くなります。

望み通りの動作をさせるために数字を多少弄る必要があるかもしれません。マウスによってはボタン 6 と 7 がスクロールホイールだったりします。その場合は 6 と 7 を最後の数字にしてください。上手く行くまで弄り続けて下さい。

Xorg に含まれている 'xev' というプログラムを使ってボタンを確認することもできます。xev を実行すると、デスクトップに小さなボックスが表示されるので、カーソルを合わせてボタンをクリックすることで、ボタンのマッピングがわかります。

xinput の調整

デバッグ時は xinput を使うことでユーザー空間で即座にボタンマップを変更できます。Logitech M505/B605 マウスの場合の実行例:

$ xinput set-button-map "$(xinput | awk -F'[=]' '/Logitech M505\/B605/ {print $2}' | awk '{print $1}')" 1 2 3 4 5 8 9

キーボードをマウスボタンにバインド

xvkbd と xbindkeys

マウスボタンをキーボードにバインドしたいとします。問題はキーの押下をエミュレートする方法がわからないということです。そこで xvkbdAUR が役に立ちます。xbindkeys と一緒に使うことができます:

$ xbindkeys --defaults >> ~/.xbindkeysrc
$ xbindkeys

xbindkeys を再起動するには以下を実行:

$ pkill -f xbindkeys
$ xbindkeys 

~/.xbindkeysrc の設定例:

"xvkbd  -text "\[F8]""
       m:0x0 + b:8
"xvkbd  -text "\[Shift]\[Left]""
       m:0x0 + b:9
"xvkbd  -text "\[Shift]\[Right]""
       m:0x0 + b:10
"xvkbd  -text 2"
       m:0x0 + b:11
"xvkbd  -text 3"
       m:0x0 + b:12

マウスボタンの番号を確認したいときは xev を使ってください。xvkbd -text では必ず大文字を入力して、括弧開き ([) を \ でエスケープしてください。

以下は xbindkeys で X のセレクションの貼り付け (中クリックのペースト) を有効にする例です。xsel と xvkbd のインストールが必要で、マウスのボタン 13 が押されたときにコマンドを実行します (~/.xbindkeysrc):

"xvkbd -no-jump-pointer -text "\D1$(xsel)" 2>/dev/null"
b:13

以下は Meta+M のキーバインドの例です:

"xvkbd  -text "\{+Super_L}m\{-Super_L}""
b:10

evrouter

プログラム (特にゲーム) によっては別の方法で入力を読み込むため、もう一つのプログラムが必要になります: evrouterAUR

evrouter コマンドで入力デバイスを読み込むには、input グループのユーザー (あるいは root) でコマンドを実行しなければなりません。ユーザーをグループに追加するには:

# gpasswd -a user input

--dump オプションを使うことで変更するボタンの名前を表示することができます:

ヒント: USB デバイスであれば udev は通常 /dev/input/by-id/ にシンボリックリンクを作成するので、それを使って特定のデバイスを指定できます。
$ evrouter --dump /dev/input/event*
device  0: /dev/input/event0: AT Translated Set 2 keyboard
device  1: /dev/input/event1: Microsoft Microsoft Trackball Explorer®
device  2: /dev/input/event2: Sleep Button
device  3: /dev/input/event3: Power Button
device  4: /dev/input/event4: Power Button
device  5: /dev/input/event5: PC Speaker
Display name: :0.0

それから変更したいボタンを押してください:

Window "(null)": # Window title
# Window "(null)": # Resource name
# Window "(null)": # Class name
"Microsoft Trackball Explorer®" "/dev/input/event1" none key/275 "fill this in!"

Window "(null)": # Window title
# Window "(null)": # Resource name
# Window "(null)": # Class name
"Microsoft Trackball Explorer®" "/dev/input/event1" none key/276 "fill this in!"

文末が "fill this in!" になっている行を設定ファイル (デフォルトでは ~/.evrouterrc) にコピーできます。例えば、evrouter に組み込まれている X11 のキーイベントエミュレータを使用して:

~/.evrouterrc
"Microsoft Trackball Explorer®" "/dev/input/event*" any key/275 "XKey/1"
"Microsoft Trackball Explorer®" "/dev/input/event*" any key/276 "XKey/2"

起動時に udev が別のデバイス番号を付与した場合を想定して 'event1' は 'event*' に変更してあります。また、'none' を 'any' に変更することで、ボタンが押されたときに修飾キーが押されていても、ルールが適用されるようにしています。フィールドの詳しい説味は evrouter(1) を見てください。

ヒント: ルールは特定のウィンドウだけに適用させることもできます。詳しくは evrouter(1) を参照。

設定ファイルの作成後、デーモンとして実行:

$ evrouter /dev/input/event*

デーモンを停止するには:

$ evrouter -q
$ rm -f /tmp/.evrouter*
ノート: /tmp/.evrouter:0.0 ファイルが存在すると evrouter は起動に失敗します。手動で削除してください。

デバイスごとの設定ファイル

Logitech G600

xorg-server 1.18.0-3 では G600 のサイドボタンはキーボードデバイスとして認識されず、おかしな挙動が発生することがあります (マウスボタンをクリックするとマウスカーソルが画面の端に飛ばされる)。強制的にキーボードボタンとして認識させるために、以下のセクションを /etc/X11/xorg.conf に追加してください:

Section "InputClass"
    Identifier "G600 misconfiguration fix"
    MatchProduct "G600"
    # Match just the keyboard section of the G600
    MatchIsKeyboard "true"
    # evdev assumes it's a mouse when it sees the absolute axis. Stop that from happening. 
    Option "IgnoreAbsoluteAxes" "on"  
EndSection

Mad Catz

Mad Catz を見てください。

Logitech M560/M545/M546

これらのマウスは Windows 8 用に設計されており、通常通りの挙動を示しません: マウスとキーボードのペアとして認識され、ボタンによっては通常のマウスボタンのイベントが発火せず、キーボードとマウスボタンのコンビネーションと認識されます。そのため Linux で"快適"なマウスとして使うのは厳しくなっています。

ドライバーを使うことで通常のマウスのように使うことができます:

M560 のカーネルモジュール (カーネル v4.2 でマージされています), M545/M546 のカーネルモジュール

また、xbindkeys でボタンをマッピングすることを推奨します。

Logitech G5 mouse: Binding + and -

If you want to bind the buttons + and - in G5/7 mouse, which normally changes DPI, you have to use g5hack [2] released by a lomoco author.

wget http://piie.net/temp/g5_hiddev.c
gcc -o g5hack g5_hiddev.c
./g5hack /dev/usb/hiddev0 3

This will change your DPI to 2000, light the 1st LED and disables DPI on-the-fly changing, so you can use it with evrouter. If you would use it frequently I suggest you to copy it to the /usr/bin directory:

# cp g5hack /usr/bin/

If you want to bind your + and - buttons you must copy the line at the bottom (one with the comment '"-" button does not function anymore' above) to the mode you will be using, like, for example, under the "case 3:" you can put it on the line with the comment 'turn on third led' above (deleting the old one before of course).

For the newest G5 mouse which is reported as "product 0xc049" original hack does not work. You have to simply change the #define MOUSE_G5 0xc041 to #define MOUSE_G5 0xc049 and recompile.

You can execute the g5hack tool at system start up using systemd unit. See Systemd#Writing unit files for detail.

If Arch is a guest virtual machine

If you want to support more than two or three mouse buttons, the capability will depend on your hypervisor software.

VMware workstation

For your Arch-based guest VM, add the below lines to its .vmx configuration file:

mouse.vusb.enable = "TRUE"
mouse.vusb.useBasicMouse = "FALSE"