Wednesday, May 1, 2024
 Popular · Latest · Hot · Upcoming
3
rated 0 times [  3] [ 0]  / answers: 1 / hits: 1624  / 1 Year ago, sun, may 28, 2023, 9:31:58

I have a laptop and I often use a Logitech G5 mouse with it. I don't like acceleration while using the mouse. Thus I have to disable the acceleration every time I plug the mouse. Is there a way to automatically disable mouse acceleration, whenever I plug my mouse?


More From » mouse

 Answers
7

Yes it can be done and it's relatively easy to do. You need to create 3 files - a udev rule, and two scripts.



UDEV Rule



A UDEV rule would detect a mouse plug event and trigger a script whenever the event happens. Create a file under /etc/udev/rules.d:



sudo gedit /etc/udev/rules.d/42-kill-mouse-accel.rules


Paste the following line in it:



ACTION=="add", ATTRS{bInterfaceClass}=="03", ENV{DISPLAY}=":0.0", ENV{XAUTHORITY}="/home/[YOUR_USER_NAME]/.Xauthority", ENV{ID_CLASS}="mouse", RUN+="/usr/local/bin/kill-mouse-accel.sh"


Note the part that says [YOUR_USER_NAME], you have to replace it with your user name.

Save and exit Gedit.



Acceleration Script



The acceleration script would be the code triggered by the UDEV rule, which in turn would fork a worker script in the background. The background script would do the actual work. We do that since we want to wait a bit before changing acceleration but we don't want to block UDEV. Create a file under /usr/local/bin:



sudo gedit /usr/local/bin/kill-mouse-accel.sh 


Paste the following code in it:



#!/bin/bash 

export DISPLAY=${DISPLAY}
/usr/local/bin/kill-mouse-accel-worker.sh &


Save and exit Gedit.



Background Acceleration Script



This script is where the command disabling mouse acceleration is called. Create a file under /usr/local/bin:



sudo gedit /usr/local/bin/kill-mouse-accel-worker.sh


Paste the following code in it:



#!/bin/bash 

sleep 2

for i in $(xinput list | grep [Mm]ouse | sed -e 's/^.*id=([0-9]*.).*$/1/')
do
echo "Found device: $i"

# The command disabling mouse acceleration
xinput set-ptr-feedback $i 10 1 1
done


Save and exit Gedit.



Finalization and Testing



Make both scripts executable:



sudo chmod +x /usr/local/bin/kill-mouse-accel.sh /usr/local/bin/kill-mouse-accel-worker.sh


Restart UDEV:



sudo service udev restart


Finally, re-plug your USB mouse and wait for a few seconds. Mouse acceleration should be disabled.



Credits



Credit goes to the author of the following blog post: http://granjow.net/udev-rules.html


[#27820] Tuesday, May 30, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
disdry

Total Points: 133
Total Questions: 128
Total Answers: 109

Location: Greenland
Member since Fri, Jul 31, 2020
4 Years ago
;