I have a G700 mouse connected to my computer. The problem with this mouse in Linux (Ubuntu) is that the sensitivity is very high. I also don't like mouse acceleration, so I've made a script that turns this off. The script looks like this
#!/bin/bash
# This script removes mouse acceleration, and lowers pointer speed
# Suitable for gaming mice, I use the Logitech G700.
# More info: http://www.x.org/wiki/Development/Documentation/PointerAcceleration/
xinput set-prop 11 'Device Accel Profile' -1
xinput set-prop 11 'Device Accel Constant Deceleration' 2.5
xinput set-prop 11 'Device Accel Velocity Scaling' 1.0
xinput set-prop 12 'Device Accel Profile' -1
xinput set-prop 12 'Device Accel Constant Deceleration' 2.5
xinput set-prop 12 'Device Accel Velocity Scaling' 1.0
Another problem with the G700 mouse is that it shows up as two different devices in xinput. This is most likely because the mouse has a wireless adapter, and is usually also connected via a usb cable (for charging). This is my output from xinput --list
(see id 11 and 12):
$ xinput --list
⎡ Virtual core pointer id=2 [master pointer (3)]
⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)]
⎜ ↳ Logitech USB Receiver id=8 [slave pointer (2)]
⎜ ↳ Logitech USB Receiver id=9 [slave pointer (2)]
⎜ ↳ Logitech Unifying Device. Wireless PID:4003 id=10 [slave pointer (2)]
⎜ ↳ Logitech G700 Laser Mouse id=11 [slave pointer (2)]
⎜ ↳ Logitech G700 Laser Mouse id=12 [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)]
This isn't usually a problem, since the id's are usually the same. But sometimes the id's of the mouse change, and that's where my question comes in.
What's the simplest way of writing a script/program that finds the id that belongs to the two listings named Logitech G700 Laser Mouse
in the output from xinput --list
, and then running the commands in the top script using those two ids?
Currently I am working on a script for a question over at askubuntu.com , which requires something similar, and I thought I'd share the simple python script that does pretty much what this question asks - find device ids and set properties:
The Script
Usage
Provide quoted name of the mouse as first command line argument:
If everything is OK, script exits silently, with exit status of
0
, or1
if anyxinput
command failed. You can uncommentprint
statement to show which ids are being configured (to later double check withxinput
that values are set alright)How it works:
Essentially,
list_ids
function lists all device ids , finds those devices that have the same name as user's mouse name and returns a list of those ids. Next we simply loop over each one of them, and of each one we set all the property-value pairs that are defined inprops
dictionary. Could be done with list of tuples as well, but dictionary is my choice here.I did it like the Answer of Raphael Ahrens but used grep and sed instead of awk and The command is now something like my_script part_of_device_name part_of_property_name_(spaces with \space) value:
My 2 cents for a Logitech Gaming Mouse G502
You can do something like the following.
So with this you first find all the IDs which match the search pattern
$SEARCH
and store them in$ids
. Then you loop over the IDs and execute the threexinput
commands.You should make sure that
$SEARCH
does not match to much, since this could result in undesired behavior.For the fun of it, same answer, but simpler way to parse and get ids:
Took me a while to figure out this can get the ids:
If the device name is always the same, in this case
Logitech G700 Laser Mouse
, you can search for matching device IDs by running