即使在 xinput/libinput 中禁用,也可以模拟鼠标中键

即使在 xinput/libinput 中禁用,也可以模拟鼠标中键

应该被禁用,但我仍能获得鼠标中键点击。当我运行 xinput list 时,我得到以下信息:

⎡ Virtual core pointer                      id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]
⎜   ↳ PixArt Microsoft USB Optical Mouse        id=9    [slave  pointer  (2)]
⎜   ↳ SQT USB Gaming Keyboard                   id=11   [slave  pointer  (2)]
⎣ Virtual core keyboard                     id=3    [master keyboard (2)]
    ↳ Virtual core XTEST keyboard               id=5    [slave  keyboard (3)]
    ↳ Power Button                              id=6    [slave  keyboard (3)]

... 还有一些非指点设备。依次检查每个设备,我发现只有 9(鼠标)的中键单击模拟设置为... 零。

Device 'PixArt Microsoft USB Optical Mouse':
    Device Enabled (152):   1
    Coordinate Transformation Matrix (154): 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000
    libinput Natural Scrolling Enabled (288):   0
    libinput Natural Scrolling Enabled Default (289):   0
    libinput Scroll Methods Available (290):    0, 0, 1
    libinput Scroll Method Enabled (291):   0, 0, 0
    libinput Scroll Method Enabled Default (292):   0, 0, 0
    libinput Button Scrolling Button (293): 2
    libinput Button Scrolling Button Default (294): 2
    libinput Middle Emulation Enabled (295):    0
    libinput Middle Emulation Enabled Default (296):    0
    libinput Accel Speed (297): 0.000000
    libinput Accel Speed Default (298): 0.000000
    libinput Accel Profiles Available (299):    1, 1
    libinput Accel Profile Enabled (300):   1, 0
    libinput Accel Profile Enabled Default (301):   1, 0
    libinput Left Handed Enabled (302): 0
    libinput Left Handed Enabled Default (303): 0
    libinput Send Events Modes Available (273): 1, 0
    libinput Send Events Mode Enabled (274):    0, 0
    libinput Send Events Mode Enabled Default (275):    0, 0
    Device Node (276):  "/dev/input/event3"
    Device Product ID (277):    1118, 203
    libinput Drag Lock Buttons (304):   <no items>
    libinput Horizontal Scroll Enabled (305):   1

然而我在游戏中还是会出现中间点击。为了证明我没有发疯,我自己编写了一个小型 SDL2 程序来检查:

#include <SDL.h>

int main(int argc, char ** argv)
{
    int quit = 0;
    SDL_Event event;
    SDL_Init(SDL_INIT_VIDEO);
    SDL_Window *window = SDL_CreateWindow("Middle click detector",
        SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, 0);

    while (!quit)
    {
        SDL_WaitEvent(&event);
        switch (event.type)
        {
        case SDL_QUIT:
            quit = 1;
            break;
        case SDL_MOUSEBUTTONDOWN:
            if (event.button.button == SDL_BUTTON_MIDDLE)
                printf("Middle clicked!\n");
            else if (event.button.button == SDL_BUTTON_LEFT)
                printf("Left clicked!\n");
            else if (event.button.button == SDL_BUTTON_RIGHT)
                printf("Right clicked!\n");
            else
                printf("What clicked?\n");
        }
    }
    SDL_DestroyWindow(window);
    SDL_Quit();
    return 0;
}

(使用 gcc sdltest.c -Wall `sdl2-config --cflags --libs` 编译)

果然,如果我按住左键并单击右键,我会得到:

Left clicked!
Right clicked!
Middle clicked!

了解 Linux 输入管道的人,能否告诉我下一步该怎么做?我不知所措。如果有人能运行测试程序并确认或否认他们有同样的问题,我将不胜感激。

答案1

我刚想用另一只鼠标测试一下。不用单击鼠标中键。

这似乎是 PixArt Microsoft USB 光电鼠标的物理(错误)特性。

相关内容