Moving the mouse while rotating the scroll wheel prevents the scrolling from actually happening in most applications. imwheel helps, but how do I run it on startup or login so that it actually works?

In detail:

I have a Windows 10 host and an Ubuntu 20.04 guest. The guest was originally installed in VMware, but I exported it (via an OVF) to VirtualBox too, for testing. In VMware Player I am using the "not optimized for gaming" mouse setting.
I have two physical mouses attached. One is the normal mouse that controls the host OS ("Host-Mouse"). The other is passed through to the guest OS ("Guest-Mouse"). The following table shows the combinations of movement and wheeling of both mouses and what the guest OS is doing:
Red means it doesn't work and it's a problem, orange means it doesn't work but it's acceptable (for me).
The problem does not occur in FireFox (so far it's the only exception I found), but in "Text Editor", "Settings", "Files" and - most problematic for me - "Qt Creator" the cursor moves but the window is not scrolled.
I found imwheel, which fixes the problem, but I cannot figure out the arcane rituals necessary to run it at startup or login such that it actually works.

Why is this so long?:

This was gonna be about the mouse wheel problem itself, but right at the end I found imwheel. I already wasted hours testing and writing all of this down, so while I cut it down, I don't want to let it all go to waste.

What I tried:

I've seen others with the same problem and no (good/applicable) solution:
Added those settings, no change.
Was already on, disabled and re-enabled it, no change.
Tried EN-US keyboard layout, no change.
Tried the commands suggested by Arwez, no change.
Tried xev | grep -n -e "ButtonPress" -e "ButtonRelease", I see activity from the mouse wheel while moving.
xinput showed "Virtual core XTEST pointer" (ID 4) and "Logitech M325" (ID 12) for both VMware and VirtualBox, and then some other slave pointers that differ between the two. I tried disabling each one individually with e.g. xinput disable 4:
Disabling "Virtual core XTEST pointer" errors out with "BadAccess".
In all other cases something was not working, but it never worked in the intended way.


scroll wheel not working when mouse is moving
Using "optimized for games" mouse in VMware and disabling mouse-integration in VirtualBox works, but it's not a great solution since that makes switching between guest and host extremely annoying.
enter image description here
enter image description here


Taken from this answer: Inconsistent and erratic mouse wheel in Linux while moving the mouse pointer
Running imwheel while already in a console, either as root or as a normal user, fixes the issue.
But none of the ways I tried to have it run automatically work:

I considered adding a file to /etc/init.d that simply runs imwheel, but I could not find a sensible explanation of how to create such a file or what the contents that I found in existing files mean (particularly parts of the comment header).

Taken from this tutorial: https://linuxconfig.org/how-to-run-script-on-startup-on-ubuntu-20-04-focal-fossa-server-desktop
I created the file /etc/systemd/system/imwheel.service with the following content:

ExecStart=/usr/bin/imwheel > /home/user/Desktop/imwheel.txt 2>&1

And ran these commands and rebooted:

chmod 664 /etc/systemd/system/imwheel.service 
systemctl daemon-reload
systemctl enable imwheel.service

The imwheel.txt file was not created.

crontab -e:
I added these two lines to crontab and rebooted:

@reboot /usr/bin/imwheel > /home/user/Desktop/imwheel.txt 2>&1
@reboot echo "a" > /home/user/Desktop/echo.txt

The two files are created, echo.txt contains "a", but imwheel.txt contains the following:

INFO: imwheel started (pid=741)
Could not open display, check shell DISPLAY variable, and export or setenv it!

This happens with both root and the normal user.

Startup Applications:
Taken from this answer: https://askubuntu.com/questions/101197/how-can-i-make-an-application-start-up-when-i-login/101200#101200
I hit the windows key, searched for "startup applications", clicked on the only result, added a new entry with the command /usr/bin/imwheel > /home/user/Desktop/imwheel.txt 2>&1.
The imwheel.txt file was not created.

1 Answer 1


Ok, this is actually not as easy as it should be. Creating a systemctl user unit is the right approach but you will need to find the right dependencies to wait for - imwheel will work only if the X display and session are ready. Here's the imwheel.service definition I am using in Manjaro 5.15 + KDE that works reliably to start imwheel once I log into my session:

ExecStart=/usr/bin/imwheel -kill -d
ExecStop=/usr/bin/pkill imwheel

In order to customize this script to your environment, run systemctl --user status and identify your window manager or something similar, look up its definition file which likely will be in /usr/lib/systemd/user and adapt the service definition above. Will most likely require you to change After=, Slice=, PartOf= and WantedBy= based on your environment.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .