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

提供: ArchWiki
2015年12月13日 (日) 20:29時点におけるKusakata (トーク | 投稿記録)による版
ナビゲーションに移動 検索に移動

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

要件

Xorg では evdev ドライバーを使います。EVentDEVice は USB 入力デバイス用の先進的なドライバーで、Xorg 標準の mouse ドライバーよりも強力です。また、mouse ドライバーよりも"ダイレクト"に制御することができ、遅延が抑えられます。

ノート: evdev はカーネルモジュールであり Xorg インプットドライバーでもあります。全ての Arch カーネルには evdev モジュールが付属しています。

Xorg 11R7.0 以降では /etc/X11/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/

設定後

Google Chrome

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

Opera

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

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

Firefox

横スクロール

Firefox 20 以上

左と右のスクロールの代わりに、戻ると進むを有効にするには、about:config で以下の設定を変更します (バージョン 32 で確認済み):

mousewheel.default.action.override_x         2
mousewheel.default.delta_multiplier_x       -100
古いバージョン

デフォルトでは、FX/MX マウスの左右スクロールは戻ると進むに翻訳されます。スクロールのままにしたい場合、about:config を開いて以下の値を変更してください:

mousewheel.horizscroll.withnokey.action      0
mousewheel.horizscroll.withnokey.numlines   -3

もしくは (Logitech G5 で確認):

mousewheel.horizscroll.withnokey.action      2
mousewheel.horizscroll.withnokey.numlines    2
ノート: numlines で正数を使うと、右と左が切り替わります。左を押すとウィンドウは右にスクロールします。

親指ボタン - 進むと戻る

ノート: 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.

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

戻る/進むを使用する最近のアプリケーションでは、デフォルトで 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 -e $(cat ~/.Xmodmap)。何か変更が必要になったときに *DM と startx のどちらを使っている場合でも ~/.Xmodmap を編集すれば良くなります。

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

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

他の方法

以下の方法は evdev ドライバーの代わりに X.org の標準のマウス入力ドライバー (xf86-input-mouse) を使います。7つまでボタンがあるマウスで動作します。下記の変更を適用するには /etc/X11/xorg.conf の InputDevice セクションを編集してください。設定後、X を再起動すれば適用されます。

IMPS/2

IntelliMouse Explorer 3.0 でテスト済みです。全てのマウスで動作するという保証はありません。

   Driver      "mouse"
   Option      "Protocol" "IMPS/2"
   Option      "Device" "/dev/input/mice"
   Option      "ZAxisMapping" "4 5 6 7"

ExplorerPS/2

Logitech MX400 と MX518 でテスト済みです。7つまでボタンがある MX シリーズのマウスで動作します。

   Driver         "mouse"
   Option         "Protocol" "ExplorerPS/2"
   Option         "Device" "/dev/input/mice"
   Option         "Buttons" "7"
   Option         "ZAxisMapping" "4 5"
   Option         "ButtonMapping" "1 2 3 6 7"

上記の設定は USB で接続する Microsoft InteliMouse Explorer 3.0 でも使えます。

Auto

Logitech MX400 でテスト済みです。7つまでボタンがある大抵のマウスで動作します。

   Driver         "mouse"
   Option         "Protocol" "auto"
   Option         "Device" "/dev/input/mice"
   Option         "Buttons" "7"
   Option         "ZAxisMapping" "4 5"
   Option         "ButtonMapping" "1 2 3 6 7"

以下の設定は Logitech MX1000 で動作することを確認しています。

   Driver         "mouse"
   Option         "Protocol" "auto"
   Option         "Device" "/dev/input/mice"
   Option         "Emulate3Buttons" "no"
   Option         "Buttons" "12"
   Option         "ZAxisMapping" "4 5 7 6 8 9"

easystroke

easystroke は X11 用のジェスチャー認識アプリケーションです。ただしマウスボタンの管理に使うこともできます。btnx と比べて多目的に使えることが主な利点です。一方で、ユーザーベースなので、ユーザーごとに設定をする必要があります。

easystroke で特別なマウスボタンを管理するには、以下を実行 (Back/Forward マウスボタンの例):

easystroke -g

Preferences タブ > Additional buttons > Add から特殊なボタンを追加してください。

ノート: In case of easystroke does not automatically detect mouse buttons, you can specify it manually. Button identifiers (numbers) can be viewed by xev.

Go to Action tab > Add action, give the new action a name, as Type choose "Key", as Details set "Alt+Left" for Back button, "Alt+Right" for Forward button, as Stroke click the proper mouse button (confirm if a warning is displayed), and voilà! Your mouse button is configured.

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

xvkbd と xbindkeys

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 xvkbd. We can use it along with 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

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

Why standard methods are not enough?

This will work great for X servers, but it seems not to work in some specific situations, like in Enemy Territory game. So I will describe a bit more advanced configuration, which work with my logitech G5 buttons - I can use all my 5 additional buttons along with 3 standard and a scroll, which gives overall 10 events to use in Enemy Territory. So here we go:

ノート: Update: evrouter can now simulate X11 key events so it is now possible to skip kbde and only use evrouter to bind keyboard buttons to your mouse.

kbde

To emulate keystroke which will be later detected in Enemy Territory we need something more advanced than xvkbd. Here comes in handy kbde, but it does not exist in the AUR yet – we have got to compile it by ourselves. We need two programs: kbde and kbde-driver. Kbde website is located on sourceforge [1], check it for download, you need only kbde-driver. Apparently, it does not work for me without some hacking. Use your editor and add

#include <linux/version.h>

somewhere near other includes in the driver/kbde.c file. (OK, I'm not sure whether it is a proper way to compile it, but it works). Assuming that you have already done that try:

tar -zxvf kbde-driver-1*
cd kbde-driver-1*
make
# if you do not have sudo just use su and type this as root
sudo make install mknod
modprobe kbde

and now you should have kbde working. If you want to use it as a non-root (yes, you want) change permissions, the quickest and dirtiest way is (note that I added my startup scripts at the end of this text):

chgrp users /dev/kbde
chmod 220 /dev/kbde

If not try reading installation instructions on the site. Now we can use it to emulate keystrokes visible even in login shells:

kbde --press 5 --release 5 -b

this will press 5 for about three times. If you want to type a string using this, rather than this use --asci=STRING, as press sometimes generates 3 strokes before it is released.

evrouter

Now we need something which will work when Enemy Territory is loaded. Apparently, xbindkeys does not work here, so we need another program: evrouterAUR [2].

OK, so now we must have evdev and we can NOT use it in X, so here is how my example /etc/X11/xorg.conf mouse section looks like:

 Section "InputDevice"
   
   Identifier  "Logitech G5"
   
   Driver      "mouse"
   Option      "Protocol" "Auto"
   Option      "Device" "/dev/input/mouse1" # probably you will need here mouse0
   Option      "Name"   "Logitech USB Gaming Mouse"
   Option      "Buttons" "8" # set this to your number of buttons
   Option      "ZAxisMapping" "4 5"

 EndSection

and now we have to restart the X server. You will run this as user, and event devices are owned by root, so you got to change the permissions at this point. Let us say we do it just like that, but I advise you to do this more carefully (note that I added my start-up scripts at the end of this text):

chgrp users /dev/input/event*
chmod 660 /dev/input/event*

Now we can use the --dump option to check what we will have to bind and to which device:

evrouter --dump /dev/input/event*
# here click buttons you would like to bind

It will give you output similar to config. Here is my example config ~/.evrouterrc with kbde usage:

"Logitech USB Gaming Mouse" "/dev/input/event.*" any key/278 "SHELL/kbde --press 2 --release 2 -b"
"Logitech USB Gaming Mouse" "/dev/input/event.*" any key/279 "SHELL/kbde --press 3 --release 3 -b"
"Logitech USB Gaming Mouse" "/dev/input/event.*" any key/274 "SHELL/kbde --press 4 --release 4 -b"
"Logitech USB Gaming Mouse" "/dev/input/event.*" any key/277 "SHELL/kbde --press 5 --release 5 -b"
"Logitech USB Gaming Mouse" "/dev/input/event.*" any key/276 "SHELL/kbde --press 6 --release 6 -b"

Same config using evrouters built in X11 key event emulator instead of kbde:

"Logitech USB Gaming Mouse" "/dev/input/event.*" any key/278 "XKey/2"
"Logitech USB Gaming Mouse" "/dev/input/event.*" any key/278 "XKey/3"
"Logitech USB Gaming Mouse" "/dev/input/event.*" any key/278 "XKey/4"
"Logitech USB Gaming Mouse" "/dev/input/event.*" any key/278 "XKey/5"
"Logitech USB Gaming Mouse" "/dev/input/event.*" any key/278 "XKey/6"

This works great, even in Enemy Territory. The "none" modifier means that I have to only press the button, other options are Ctrl+Alt and so on. Here I use "any" because "none" means that after pressing Shift, Ctrl, or Alt, our buttons would not work. Also note that it accepts regular expressions for mouse name and event path. Then, after setting up a config, run service with:

evrouter /dev/input/event* >> /dev/null

or change the event* to a device corresponding to your mouse -- but be aware that the numbers are changing sometimes. It will work in background, while outputting some annoying messages, so we stream it to /dev/null. If something went wrong, run it without streaming and check what it outputs. If you want to end it, you have to delete /tmp/evrouter.* manually. Here is a script to kill evrouter:

#!/bin/bash
evrouter -q
rm -f /tmp/.evrouter*

and here is one to start it:

#!/bin/bash
mydevicename="Logitech USB Gaming Mouse"

device=$(evrouter -D /dev/input/event* | grep "$mydevicename") | cut -d ":" -f 2
evrouter $device > /dev/null

You have to edit the mydevicename variable to its proper value (the one which is shown by evrouter -D), or just change it to listen on all events by changing device var to /dev/input/event*. OK, I have saved them in /usr/bin/. Now, everything should be ready for use!

Logitech G5 マウスの + と - のバインド

G5/7 マウスに付いているボタン +- をバインドしたい場合 (通常は DPI を変更します)、lomoco の作者によって作成された g5hack [3] を使う必要があります。

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.

ユーザーツール

imwheelAUR provides configurable mouse wheel and button mapping. It can be configured globally or for individual processes.

Sample ~/.imwheelrc to enable back/forward thumb buttons for all applications and increased scroll speed in Chromium:

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

lomoco for Logitech MX mice will help you set the proper resolution, enable or disable smart scroll (with boot time support too!), etc. lomoco is available from the [community] repository and can be installed with the following command:

Be sure to look at /etc/udev/lomoco_mouse.conf and set up the the options you want to be automatically applied when the mouse gets loaded by udev.

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

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

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 Mouse

Mad Catz Mouse を見て下さい。

Logitech M560/M545/M546

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

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

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

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

参照