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?

  • @Braiam isn't it harder for people to find the question lacking those tags? – Nicolay Doytchev Dec 26 '13 at 3:22
  • 1
    Please, read the last 4 questions of this Meta Question meta.askubuntu.com/q/7819/169736 – Braiam Dec 26 '13 at 3:26
  • I see. Yeah, also search finds it reasonably well without the tags. Thanks! – Nicolay Doytchev Dec 26 '13 at 4:04

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


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:


/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:


sleep 2 

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

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

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.


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

| improve this answer | |
  • I don't see difference. – emrecnl Nov 6 '15 at 18:42

I have a similar issue and I have developed a different solution.

I've written a Python script that listens for udev events and runs some commands whenever a device is plugged or unplugged. In my case, one of the commands disables mouse acceleration. I've choosen this solution because it does not require root permissions, and thus can be applied on any Linux system. I just leave the Python script running in background and don't worry about it anymore.

All the scripts are available at https://github.com/denilsonsa/small_scripts , and they are also copied/mirrored below, for reference.


#!/usr/bin/env python3

import functools
import os.path
import pyudev
import subprocess
import time

def main():
    BASE_PATH = os.path.dirname(os.path.realpath(os.path.abspath(__file__)))
    path = functools.partial(os.path.join, BASE_PATH)
    call = lambda x, *args: subprocess.call([path(x)] + list(args))

    context = pyudev.Context()
    monitor = pyudev.Monitor.from_netlink(context)


    for device in iter(monitor.poll, None):
        # Wait a short amount of time to let the device get ready.


if __name__ == '__main__':



xsp_microsoft() {
    xinput set-prop 'Microsoft  Microsoft Basic Optical Mouse v2.0 ' "$@"
xsp_logitech() {
    xinput set-prop 'Logitech USB Laser Mouse' "$@"

xsp_microsoft 'Device Accel Profile' -1
xsp_logitech 'Device Accel Profile' -1

xsp_microsoft 'Device Accel Constant Deceleration' 1.5
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.