我想禁用由 bash 脚本控制的鼠标移动,因此xdotool可以接管并撞击鼠标,否则不会成为问题。
但是,我需要按钮保持工作,所以简单地禁用鼠标不是一个选项。
这与这个问题相同,但那里的解决方案对我不起作用。我的鼠标似乎没有这些属性。
xinput list显示鼠标 3 次。ID 10 拥有最多的属性,其他两个具有选项的子集。
的输出xinput list-props 10:
Device 'Logitech Gaming Mouse G502':
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 Accel Speed (290): 0.000000
libinput Accel Speed Default (291): 0.000000
libinput Accel Profiles Available (292): 1, 1
libinput Accel Profile Enabled (293): 1, 0
libinput Accel Profile Enabled Default (294): 1, 0
libinput Natural Scrolling Enabled (295): 0
libinput Natural Scrolling Enabled Default (296): 0
libinput Send Events Modes Available (275): 1, 0
libinput Send Events Mode Enabled (276): 0, 0
libinput Send Events Mode Enabled Default (277): 0, 0
libinput Left Handed Enabled (297): 0
libinput Left Handed Enabled Default (298): 0
libinput Scroll Methods Available (299): 0, 0, 1
libinput Scroll Method Enabled (300): 0, 0, 0
libinput Scroll Method Enabled Default (301): 0, 0, 0
libinput Button Scrolling Button (302): 2
libinput Button Scrolling Button Default (303): 2
libinput Middle Emulation Enabled (304): 0
libinput Middle Emulation Enabled Default (305): 0
Device Node (278): "/dev/input/event2"
Device Product ID (279): 1133, 49277
libinput Drag Lock Buttons (306): <no items>
libinput Horizontal Scroll Enabled (307): 1
Run Code Online (Sandbox Code Playgroud)
我尝试弄乱坐标变换矩阵,但据我所知,它没有任何作用。
其他属性似乎都不能帮助我 - 有没有其他方法可以解决这个问题?
编辑:输出xinput list:
? Virtual core pointer id=2 [master pointer (3)]
? ? Virtual core XTEST pointer id=4 [slave pointer (2)]
? ? Logitech Gaming Mouse G502 id=11 [slave pointer (2)]
? ? Logitech Gaming Mouse G502 id=10 [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)]
? Power Button id=7 [slave keyboard (3)]
? Logitech G510 Gaming Keyboard id=8 [slave keyboard (3)]
? Logitech G510 Gaming Keyboard id=9 [slave keyboard (3)]
? Eee PC WMI hotkeys id=12 [slave keyboard (3)]
? Logitech Gaming Mouse G502 id=13 [slave keyboard (3)]
Run Code Online (Sandbox Code Playgroud)
使用时,xinput test <ID>我注意到只有 ID 为 10 的设备响应了任何事件。
显然,改变坐标变换矩阵确实有效,我只是做错了方法。
将其设置为全 0 矩阵根本不会执行任何操作。更改随机值可能会产生影响,也可能不会产生影响。
最后,我注意到,增大矩阵右下角的条目会减慢我的鼠标速度。因此,将此值更改为较大的值即可达到预期的效果。
例如:
xinput set-prop 10 154 1 0 0 0 1 0 0 0 1000000
这仅适用于 ID 为 10 的鼠标设备。
编辑:将其他 1 值设置为较小的值(例如 0)也会使其变慢。所以这也有效:xinput set-prop 10 154 0 0 0 0 0 0 0 0 1
更好的是,xinput test 10不输出任何东西。
然而,当与 xdotool 一起使用时,我注意到光标跳到屏幕的左上角。我不确定这是否仍在这个问题的范围内,但这仍然是一个问题。
Edit2:看来跳转到屏幕左上角是由 引起的xdotool mousemove。如果在使用上述矩阵设置发出此类命令后移动鼠标,鼠标指针会跳到左上角。
为了防止这种情况发生,您只需进行相对运动即可。例如这样的:xdotool mousemove X Y mousemove_relative 1 1 mousemove_relative -- -1 -1。这会将指针移动到提供的 X 和 Y 坐标,并且不受进一步鼠标移动的影响。