linux – 禁用滚轮水平按钮(后退/前进)

我最近买了一台罗技M500:

Bus 002 Device 004: ID 046d:c069 Logitech, Inc. M500 Laser Mouse

它有九个按钮,我可以识别:

>左侧两个
>左,右
>轮压机
>滚轮向上滚动,滚轮向下滚动
>轮压左,轮按右

最后两个让我疯了.每次我尝试点击滚轮时,我都会意外地点击“左转滚轮”按钮,Firefox会转到最后访问过的页面.这很烦人.

够容易吧?只需找出xev显示哪些按钮并禁用它们.错误! xev不会生成“ButtonPress / ButtonRelease”事件,但很奇怪
“LeaveNotify / EnterNotify / KeymapNotify”对:

 LeaveNotify event, serial 40, synthetic NO, window 0x4a00001,
    root 0x94, subw 0x0, time 2344319, (104,86), root:(113,207),
    mode NotifyGrab, detail NotifyAncestor, same_screen YES,
    focus YES, state 0

EnterNotify event, serial 40, synthetic NO, window 0x4a00001,
    root 0x94, subw 0x0, time 2344319, (104,86), root:(113,207),
    mode NotifyUngrab, detail NotifyAncestor, same_screen YES,
    focus YES, state 0

KeymapNotify event, serial 40, synthetic NO, window 0x0,
    keys:  4294967188 0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   
           0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   

现在肯定的是,4294967188(如果有帮助的话,二进制补码中的-108为32位整数)将是键码,对吧?又错了!水平滚轮左/右和侧后/前按钮的数字相同.

这是我的设备的xinput列表:

Logitech USB Laser Mouse                    id=15   [slave  pointer  (2)]
    Reporting 7 classes:
        Class originated from: 15. Type: XIButtonClass
        Buttons supported: 16
        Button labels: "Button Left" "Button Middle" "Button Right" "Button Wheel Up" "Button Wheel Down" "Button Horiz Wheel Left" "Button Horiz Wheel Right" "Button Side" "Button Extra" "Button Forward" "Button Back" "Button Task" "Button Unknown" "Button Unknown" "Button Unknown" "Button Unknown"
        Button state:
        Class originated from: 15. Type: XIValuatorClass
        Detail for Valuator 0:
          Label: Rel X
          Range: -1.000000 - -1.000000
          Resolution: 1 units/m
          Mode: relative
        Class originated from: 15. Type: XIValuatorClass
        Detail for Valuator 1:
          Label: Rel Y
          Range: -1.000000 - -1.000000
          Resolution: 1 units/m
          Mode: relative
        Class originated from: 15. Type: XIValuatorClass
        Detail for Valuator 2:
          Label: Rel Horiz Wheel
          Range: -1.000000 - -1.000000
          Resolution: 1 units/m
          Mode: relative
        Class originated from: 15. Type: XIValuatorClass
        Detail for Valuator 3:
          Label: Rel Vert Wheel
          Range: -1.000000 - -1.000000
          Resolution: 1 units/m
          Mode: relative
        Class originated from: 15. Type: XIScrollClass
        Scroll info for Valuator 2
          type: 2 (horizontal)
          increment: 1.000000
          flags: 0x0
        Class originated from: 15. Type: XIScrollClass
        Scroll info for Valuator 3
          type: 1 (vertical)
          increment: -1.000000
          flags: 0x2 ( preferred )

它似乎按照正常情况映射按钮.那么当我在循环中编写一个调用“xinput query-state $DEVNO”的小脚本并按下可怕的按钮时会发生什么?你猜到了:

2 classes :
ButtonClass
    button[1]=up
    button[2]=up
    button[3]=up
    button[4]=up
    button[5]=up
    button[6]=up
    button[7]=up
    button[8]=up
    button[9]=up
    button[10]=up
    button[11]=up
    button[12]=up
    button[13]=up
    button[14]=up
    button[15]=up
    button[16]=up
ValuatorClass Mode=Relative Proximity=In
    valuator[0]=538
    valuator[1]=456
    valuator[2]=-2
    valuator[3]=-464

他们总是表现为“向上”,尽管他们显然是“向下”.确实生成正确的ButtonPress事件的鼠标按钮(例如左/右)确实会像他们应该的那样显示广告“向下”.

解决方法:

我有一台罗技M325,它还使用按钮8和9进行滚轮的左右倾斜.我用这个脚本来禁用它们:

#!/bin/bash

set -eu

MOUSE_ID=$(xinput --list | grep Logitech | sed -r 's/.*id=([0-9]+).*/\1/')

if [ -n "$MOUSE_ID" ]; then
    xinput set-button-map $MOUSE_ID 1 2 3 4 5 6 7 0 0
fi
上一篇:jQuery(一)——mouse事件练习:图片跟随


下一篇:mongodb-2.6.0 在win7 64下的安装和服务启动