Can I make middle-mouse scrolling on linux behave more like autoscrolling on windows?How can I turn off...
How does increase in volume change the speed of reaction in production of NO2?
Singlequote and backslash
Why does my electric oven present the option of 40A and 50A breakers?
Is a hash a zero-knowledge proof?
What is the most important characteristic of New Weird as a genre?
Why is there a need to modify system call tables in Linux?
Why does the UK have more political parties than the US?
How can a single Member of the House block a Congressional bill?
Accidentally cashed a check twice
What is a simple, physical situation where complex numbers emerge naturally?
Joist hangers to use for rough cut 2x8 (2 3/4" x 8 3/4")?
Looking for an old image of designing a cpu with plan laid out / being edited on a literal floor
Could IPv6 make NAT / port numbers redundant?
How can I offer a test ride while selling a bike?
What are the problems in teaching guitar via Skype?
If a problem only occurs randomly once in every N times on average, how many tests do I have to perform to be certain that it's now fixed?
Bringing Food from Hometown for Out-of-Town Interview?
What is a natural deduction proof from ~(A↔B) to ~(A→B)?
Applicants clearly not having the skills they advertise
Can a helicopter mask itself from Radar?
Modern approach to radio buttons
How can I grammatically understand "Wir über uns"?
Orientable with respect to complex cobordism?
What does it mean by "d-ism of Leibniz" and "dotage of Newton" in simple English?
Can I make middle-mouse scrolling on linux behave more like autoscrolling on windows?
How can I turn off “middle mouse button paste” functionality in all programs?Disable/modify middle-click-to-paste in X11/XorgMouse sensitivity confusionNouveau cursor “tearing”Ignore brief mouse click/releasesHalt the mouse wheel on keyboard key downHow can I make windows stay opaque when inactive?Dell Precision Trackpoint Odd configurationKali Linux 2016 Rolling Inverted Mouse Scrollinglibinput button scrolling: delay between button press and scroll
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
For any who do not know what autoscrolling is, you can experience it in Chromium with the autoscroll extension (speed set to 3), and in firefox by enabling the 'use autoscroll' option.
Enabling middle-mouse scrolling is not that hard, in fact all I had to do was this:
xinput set-prop 8 "libinput Scroll Method Enabled" 0, 0, 1
However it does not behave the way I want at all.
Functionality I want:
- When clicked, it enables 'locked scrolling' so moving the mouse up or down without holding down the button should scroll. Until Middle Mouse is pressed again.
- When clicked or held, a symbol indicating the starting position appears.
- When clicked or held, moving the mouse up/down from the initial point where you clicked should enable 'automatic scrolling' in that direction with speeds based on how far you moved the mouse, moving the mouse back to the starting point stops scrolling
Functionality I've got:
- When clicked it does nothing (well, does what it's bound to do by the DE, an option I'd like to disable as I am fully accustomed to ctrl+v for pasting things)
- When held, mouse movement behaves like the scroll wheel, e.g. scrolling requires constant movement of the mouse, there is no 'automatic scrolling' available.
As you can see that's a lot of missing functionality. Sure, I can just use the autoscroll extension for chrome at the start and it works, for chrome. But I want it systemwide, which is how it works in windows.
Now, maybe it would be a bit much work to get the complete autoscrolling functionality systemwide (or would it? I wouldn't know...) and depending on how it's implemented, it could cause problems in some applications that use the middle mouse button for a keybind (overriding application keybinds is a big no-no for sure).
But I would be quite happy if I could just get the automatic scrolling enabled for when the middle mouse button is held, even if perhaps not the complete functionality, it would be close enough.
xorg libinput
add a comment |
For any who do not know what autoscrolling is, you can experience it in Chromium with the autoscroll extension (speed set to 3), and in firefox by enabling the 'use autoscroll' option.
Enabling middle-mouse scrolling is not that hard, in fact all I had to do was this:
xinput set-prop 8 "libinput Scroll Method Enabled" 0, 0, 1
However it does not behave the way I want at all.
Functionality I want:
- When clicked, it enables 'locked scrolling' so moving the mouse up or down without holding down the button should scroll. Until Middle Mouse is pressed again.
- When clicked or held, a symbol indicating the starting position appears.
- When clicked or held, moving the mouse up/down from the initial point where you clicked should enable 'automatic scrolling' in that direction with speeds based on how far you moved the mouse, moving the mouse back to the starting point stops scrolling
Functionality I've got:
- When clicked it does nothing (well, does what it's bound to do by the DE, an option I'd like to disable as I am fully accustomed to ctrl+v for pasting things)
- When held, mouse movement behaves like the scroll wheel, e.g. scrolling requires constant movement of the mouse, there is no 'automatic scrolling' available.
As you can see that's a lot of missing functionality. Sure, I can just use the autoscroll extension for chrome at the start and it works, for chrome. But I want it systemwide, which is how it works in windows.
Now, maybe it would be a bit much work to get the complete autoscrolling functionality systemwide (or would it? I wouldn't know...) and depending on how it's implemented, it could cause problems in some applications that use the middle mouse button for a keybind (overriding application keybinds is a big no-no for sure).
But I would be quite happy if I could just get the automatic scrolling enabled for when the middle mouse button is held, even if perhaps not the complete functionality, it would be close enough.
xorg libinput
add a comment |
For any who do not know what autoscrolling is, you can experience it in Chromium with the autoscroll extension (speed set to 3), and in firefox by enabling the 'use autoscroll' option.
Enabling middle-mouse scrolling is not that hard, in fact all I had to do was this:
xinput set-prop 8 "libinput Scroll Method Enabled" 0, 0, 1
However it does not behave the way I want at all.
Functionality I want:
- When clicked, it enables 'locked scrolling' so moving the mouse up or down without holding down the button should scroll. Until Middle Mouse is pressed again.
- When clicked or held, a symbol indicating the starting position appears.
- When clicked or held, moving the mouse up/down from the initial point where you clicked should enable 'automatic scrolling' in that direction with speeds based on how far you moved the mouse, moving the mouse back to the starting point stops scrolling
Functionality I've got:
- When clicked it does nothing (well, does what it's bound to do by the DE, an option I'd like to disable as I am fully accustomed to ctrl+v for pasting things)
- When held, mouse movement behaves like the scroll wheel, e.g. scrolling requires constant movement of the mouse, there is no 'automatic scrolling' available.
As you can see that's a lot of missing functionality. Sure, I can just use the autoscroll extension for chrome at the start and it works, for chrome. But I want it systemwide, which is how it works in windows.
Now, maybe it would be a bit much work to get the complete autoscrolling functionality systemwide (or would it? I wouldn't know...) and depending on how it's implemented, it could cause problems in some applications that use the middle mouse button for a keybind (overriding application keybinds is a big no-no for sure).
But I would be quite happy if I could just get the automatic scrolling enabled for when the middle mouse button is held, even if perhaps not the complete functionality, it would be close enough.
xorg libinput
For any who do not know what autoscrolling is, you can experience it in Chromium with the autoscroll extension (speed set to 3), and in firefox by enabling the 'use autoscroll' option.
Enabling middle-mouse scrolling is not that hard, in fact all I had to do was this:
xinput set-prop 8 "libinput Scroll Method Enabled" 0, 0, 1
However it does not behave the way I want at all.
Functionality I want:
- When clicked, it enables 'locked scrolling' so moving the mouse up or down without holding down the button should scroll. Until Middle Mouse is pressed again.
- When clicked or held, a symbol indicating the starting position appears.
- When clicked or held, moving the mouse up/down from the initial point where you clicked should enable 'automatic scrolling' in that direction with speeds based on how far you moved the mouse, moving the mouse back to the starting point stops scrolling
Functionality I've got:
- When clicked it does nothing (well, does what it's bound to do by the DE, an option I'd like to disable as I am fully accustomed to ctrl+v for pasting things)
- When held, mouse movement behaves like the scroll wheel, e.g. scrolling requires constant movement of the mouse, there is no 'automatic scrolling' available.
As you can see that's a lot of missing functionality. Sure, I can just use the autoscroll extension for chrome at the start and it works, for chrome. But I want it systemwide, which is how it works in windows.
Now, maybe it would be a bit much work to get the complete autoscrolling functionality systemwide (or would it? I wouldn't know...) and depending on how it's implemented, it could cause problems in some applications that use the middle mouse button for a keybind (overriding application keybinds is a big no-no for sure).
But I would be quite happy if I could just get the automatic scrolling enabled for when the middle mouse button is held, even if perhaps not the complete functionality, it would be close enough.
xorg libinput
xorg libinput
edited 44 mins ago
Cestarian
asked Sep 30 '18 at 10:58
CestarianCestarian
90411527
90411527
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
(The script here has been improved quite a lot by other users, I recommend using the version in Azerothian's answer instead.)
I have a working solution in the form of a bash script, it's not really perfect but it gets the job done, at least for my purposes.
The script requires xdotool and xinput and xsel. sxhkd is the recommended solution for binding the script to middle-mouse.
(Note: the script is dash compatible, change #!/bin/bash to #!/bin/dash to use the faster interpreter if it is installed)
#!/bin/bash
#Autoscroll (hold only)
echo -n | xsel -n -i
eval $(xdotool getmouselocation --shell)
starty=$Y
mouseid=$(xinput --list | grep -i -m 1 'mouse' | grep -o 'id=[0-9]+' | grep -o '[0-9]+')
toggle=0
while [ $toggle -eq 0 ]
do
sleep 0.02
mmouse=$(xinput --query-state $mouseid | grep 'button[2' | cut -d = -f2)
toggle=$(xinput --query-state $mouseid | grep 'button[2' | grep -c up)
eval $(xdotool getmouselocation --shell)
curry=$Y
#Scroll down
while [ $curry -gt $starty ] && [ $toggle -eq 0 ]
do
eval $(xdotool getmouselocation --shell)
curry=$Y
speed=$(expr $curry / 100 - $starty / 100)
xdotool click --repeat $speed --delay 1 5
toggle=$(xinput --query-state $mouseid | grep 'button[2' | grep -c up)
sleep 0.02
done
#Scroll up
while [ $curry -lt $starty ] && [ $toggle -eq 0 ]
do
eval $(xdotool getmouselocation --shell)
curry=$Y
speed=$(expr $curry / 100 - $starty / 100 | sed 's:-::')
xdotool click --repeat $speed --delay 1 4
toggle=$(xinput --query-state $mouseid | grep 'button[2' | grep -c up)
sleep 0.02
done
done
And here's the sxhkd configuration: ./.config/.sxhkd/sxhkdrc
~button2
"/path/to/autoscroll"
@button2
~control + c
echo -n | xsel -n -i
~control + shift + c
echo -n | xsel -n -i
~control + x
echo -n | xsel -n -i
The above script when triggered by sxhkd will allow for system-wide autoscrolling, but only when the middle mouse button is held. Clicking middle mouse will function as normal but with the pasting functionality disabled (except for circumstances where you do not use ctrl+c or ctrl+x to copy things).
If you prefer to leave middle click pasting enabled (not recommended, unless you like accidentally pasting things), use this instead:
~button2
"/path/to/autoscroll"
@button2
And also comment out or remove the first line of the autoscroll script (echo -n | xsel -n -i line)
There are a few reasons why I use sxhkd and not xbindkeys.
- sxhkd allows you to make the click for the bound button go through normally first before triggering the script (this is what ~button2 does), this enables the middle mouse button to maintain it's prior functionality alongside with executing this script.
- For some reason for both sxhkd and xbindkeys, if I tried to bind the script to middle mouse it would only work if the libinput mousewheel emulation is turned on, if I turn it off, the script simply won't run through these programs (even if it works fine on it's own) in short, the solution to this was sxhkd's @ prefix, hence @button2.
The good news is that holding down middle mouse to scroll works flawlessly (as long as you are ok with not being able to paste things with middle mouse).
The bad news is that clicking middle mouse to toggle auto-scrolling has some quite serious issues which is why I did not leave it in the default script.
In order to enable clicking to toggle autoscrolling replace all instances of:
toggle=$(xinput --query-state $mouseid | grep 'button[2' | grep -c up)
With:
if [ "$mmouse" = "down" ]; then
toggle=$(xinput --query-state $mouseid | grep 'button[2' | grep -c up)
else
toggle=$(xinput --query-state $mouseid | grep 'button[' | sort | grep -c down)
fi
Issues with both holding and clicking to scroll:
- It scrolls rather fast at minimum speed, while probably appropriate for most users, I personally would prefer slower speeds. The most likely solution for this is lowering the scrolling speed for libinput, this is sadly not as easy as it should be (hence not yet tested by me).
- Horizontal scrolling is not implemented, however it would be easy to implement (I just never use it so I had no reason to). Currently the entire script is based around the Y axis, copying what is already here and including the X axis would be a simple matter, and instead of mouse button 4 and 5 which are for vertical scrolling, you would use mouse button 6 and 7 for horizontal scrolling. (Fixed in Azerothian's version)
- There is no icon to indicate the starting position of the scrolling, and there is no cursor change to indicate that scrolling is active. I assume this shouldn't be that hard to solve, but I have assumed wrong before...
- If your mouse cursor is at a scrollable location (like your browser tabs, or your taskbar, where you can scroll between tasks/tabs) when you release the button, it will scroll.
Issues with clicking to scroll:
- Does not always trigger (this is a fault of sxhkd's current configuration, if I only use @button2 for the script and omit ~button2, it works perfectly fine, however, it would also mean that you could no longer use middle mouse to say open links in a new tab in a browser because the click would no longer be forwarded through)
- Does not detect when middle click was actually used for something else. (e.g. if you use middle click to open a link in a new tab, scrolling is most likely going to be activated as a side effect of that middle click, a possible solution would be having a program that detects the cursor status and would only activate the script if the cursor is neutral or hovering text, or at least does not activate when hovering links, however I know no such software)
- Pressing middle mouse again to stop scrolling does not work (you can press any other mouse button to stop scrolling instead however, like left or right click, so it's no big deal really) this can probably be solved by fiddling with the script a little bit but I didn't get around to it.
- Scrolling is not bound to the cursor's starting position, rather the cursor itself (this is not an issue when holding down the button). What this means, is lets say you're in a browser and you use this autoscrolling script, if you move the mouse too high up the screen, instead of scrolling up and down on the current page you will start scrolling through your tabs instead, which is less than ideal for sure as it means you must be careful of where you move your cursor while scrolling.
The first issue can sort of be solved by configuring ./.config/.sxhkd/sxhkdrc like this
@button2
"/path/to/autoscroll"
However not only does this break your ability to hold-to-scroll, your middle mouse button will only function for autoscrolling, you will not be able to use the middle mouse button to open links in new tabs anymore without the ~button2 line. If you never use that functionality and never use middle mouse to paste things, this may suit you fine, but otherwise I'd advise against it.
The bottom line is, it works great for holding middle mouse to autoscroll, and it works not well at all for clicking to toggle autoscroll (which is why I left it disabled)
This satisfies my needs as requested by the OP however I will be waiting for a while for better answers if anyone happens to have a better solution before I mark this answer as the solution.
add a comment |
I don't have a better answer outside that i have improved (in my opinion) the script cestarian provided, I wanted the horizontal scroll, and I also had issues with my Logitech mouse not being picked up correctly.
I also didn't see the reason as to having so many loops where a single loop will be much faster and allows for multi direction scrolling on the same cycle :D
Tested on xUbuntu 18.04.2 LTS
sudo apt install xdotool xsel sxhkd
~/.config/sxkhd/sxhkdrc
~button2
"~/.config/sxkhd/autoscroll.sh"
@button2
~control + c
echo -n | xsel -n -i
~control + shift + c
echo -n | xsel -n -i
~control + x
echo -n | xsel -n -i
~/.config/sxkhd/autoscroll.sh
#!/bin/dash
# Autoscroll (hold only)
middlemousebutton=2
mousescrollup=4
mousescrolldown=5
mousescrollleft=6
mousescrollright=7
enableverticalscroll=1
enablehorizontalscroll=1
## Danger below :D
echo -n | xsel -n -i
eval $(xdotool getmouselocation --shell)
starty=$Y
startx=$X
toggle=$middlemousebutton
while [ $toggle -eq $middlemousebutton ]
do
eval $(xdotool getmouselocation --shell)
curry=$Y
currx=$X
if [ $enableverticalscroll -eq 1 ]
then
if [ $curry -gt $starty ]
then
speedy=$(expr $curry / 100 - $starty / 100)
if [ $speedy -gt 0 ]
then
xdotool click --repeat $speedy --delay 1 $mousescrolldown
fi
else
speedy=$(expr $curry / 100 - $starty / 100 | sed 's:-::')
if [ $speedy -gt 0 ]
then
xdotool click --repeat $speedy --delay 1 $mousescrollup
fi
fi
fi
if [ $enablehorizontalscroll -eq 1 ]
then
if [ $currx -gt $startx ]
then
speedx=$(expr $currx / 100 - $startx / 100)
if [ $speedx -gt 0 ]
then
xdotool click --repeat $speedx --delay 1 $mousescrollright
fi
else
speedx=$(expr $currx / 100 - $startx / 100 | sed 's:-::')
if [ $speedx -gt 0 ]
then
xdotool click --repeat $speedx --delay 1 $mousescrollleft
fi
fi
fi
toggle=$(xinput --list "Virtual core pointer" | grep -i -m 1 "Button state:" | grep -o "[$middlemousebutton]+")
sleep 0.02
done
chmod +x ~/.config/sxkhd/autoscroll.sh
Make sure you add sxhkd to Session and Startup -> Autostart Applications
and everything should work on next boot
New contributor
Nice, I wanted horizontal scrolling too but was too lazy to implement it. Also that defaultstate thing, I don't even remember how that was supposed to work (messy little script isn't it?...), but setting it to 1 fixed it on my other mouse, your script definitely is nicer. My defaultstate should have been 2 though according to how I'm supposed to find it out, but it only works if set to 1.
– Cestarian
2 days ago
good point on the getting the state, i made a mistake in regards to defaultstate, i have updated the above to reflect its actual purpose. it is now activestate and i updated the instructions to match ^^
– Azerothian
yesterday
1
I just had epiphany!!! we don't need to use the target mouse to check for the state of the mouse button, i found that we can look at the button state in the virtual core pointer, if 2 then middle mouse button is pressed. solves the issue when switching between two different mice. i have updated the script with my current solution.
– Azerothian
yesterday
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f472398%2fcan-i-make-middle-mouse-scrolling-on-linux-behave-more-like-autoscrolling-on-win%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
(The script here has been improved quite a lot by other users, I recommend using the version in Azerothian's answer instead.)
I have a working solution in the form of a bash script, it's not really perfect but it gets the job done, at least for my purposes.
The script requires xdotool and xinput and xsel. sxhkd is the recommended solution for binding the script to middle-mouse.
(Note: the script is dash compatible, change #!/bin/bash to #!/bin/dash to use the faster interpreter if it is installed)
#!/bin/bash
#Autoscroll (hold only)
echo -n | xsel -n -i
eval $(xdotool getmouselocation --shell)
starty=$Y
mouseid=$(xinput --list | grep -i -m 1 'mouse' | grep -o 'id=[0-9]+' | grep -o '[0-9]+')
toggle=0
while [ $toggle -eq 0 ]
do
sleep 0.02
mmouse=$(xinput --query-state $mouseid | grep 'button[2' | cut -d = -f2)
toggle=$(xinput --query-state $mouseid | grep 'button[2' | grep -c up)
eval $(xdotool getmouselocation --shell)
curry=$Y
#Scroll down
while [ $curry -gt $starty ] && [ $toggle -eq 0 ]
do
eval $(xdotool getmouselocation --shell)
curry=$Y
speed=$(expr $curry / 100 - $starty / 100)
xdotool click --repeat $speed --delay 1 5
toggle=$(xinput --query-state $mouseid | grep 'button[2' | grep -c up)
sleep 0.02
done
#Scroll up
while [ $curry -lt $starty ] && [ $toggle -eq 0 ]
do
eval $(xdotool getmouselocation --shell)
curry=$Y
speed=$(expr $curry / 100 - $starty / 100 | sed 's:-::')
xdotool click --repeat $speed --delay 1 4
toggle=$(xinput --query-state $mouseid | grep 'button[2' | grep -c up)
sleep 0.02
done
done
And here's the sxhkd configuration: ./.config/.sxhkd/sxhkdrc
~button2
"/path/to/autoscroll"
@button2
~control + c
echo -n | xsel -n -i
~control + shift + c
echo -n | xsel -n -i
~control + x
echo -n | xsel -n -i
The above script when triggered by sxhkd will allow for system-wide autoscrolling, but only when the middle mouse button is held. Clicking middle mouse will function as normal but with the pasting functionality disabled (except for circumstances where you do not use ctrl+c or ctrl+x to copy things).
If you prefer to leave middle click pasting enabled (not recommended, unless you like accidentally pasting things), use this instead:
~button2
"/path/to/autoscroll"
@button2
And also comment out or remove the first line of the autoscroll script (echo -n | xsel -n -i line)
There are a few reasons why I use sxhkd and not xbindkeys.
- sxhkd allows you to make the click for the bound button go through normally first before triggering the script (this is what ~button2 does), this enables the middle mouse button to maintain it's prior functionality alongside with executing this script.
- For some reason for both sxhkd and xbindkeys, if I tried to bind the script to middle mouse it would only work if the libinput mousewheel emulation is turned on, if I turn it off, the script simply won't run through these programs (even if it works fine on it's own) in short, the solution to this was sxhkd's @ prefix, hence @button2.
The good news is that holding down middle mouse to scroll works flawlessly (as long as you are ok with not being able to paste things with middle mouse).
The bad news is that clicking middle mouse to toggle auto-scrolling has some quite serious issues which is why I did not leave it in the default script.
In order to enable clicking to toggle autoscrolling replace all instances of:
toggle=$(xinput --query-state $mouseid | grep 'button[2' | grep -c up)
With:
if [ "$mmouse" = "down" ]; then
toggle=$(xinput --query-state $mouseid | grep 'button[2' | grep -c up)
else
toggle=$(xinput --query-state $mouseid | grep 'button[' | sort | grep -c down)
fi
Issues with both holding and clicking to scroll:
- It scrolls rather fast at minimum speed, while probably appropriate for most users, I personally would prefer slower speeds. The most likely solution for this is lowering the scrolling speed for libinput, this is sadly not as easy as it should be (hence not yet tested by me).
- Horizontal scrolling is not implemented, however it would be easy to implement (I just never use it so I had no reason to). Currently the entire script is based around the Y axis, copying what is already here and including the X axis would be a simple matter, and instead of mouse button 4 and 5 which are for vertical scrolling, you would use mouse button 6 and 7 for horizontal scrolling. (Fixed in Azerothian's version)
- There is no icon to indicate the starting position of the scrolling, and there is no cursor change to indicate that scrolling is active. I assume this shouldn't be that hard to solve, but I have assumed wrong before...
- If your mouse cursor is at a scrollable location (like your browser tabs, or your taskbar, where you can scroll between tasks/tabs) when you release the button, it will scroll.
Issues with clicking to scroll:
- Does not always trigger (this is a fault of sxhkd's current configuration, if I only use @button2 for the script and omit ~button2, it works perfectly fine, however, it would also mean that you could no longer use middle mouse to say open links in a new tab in a browser because the click would no longer be forwarded through)
- Does not detect when middle click was actually used for something else. (e.g. if you use middle click to open a link in a new tab, scrolling is most likely going to be activated as a side effect of that middle click, a possible solution would be having a program that detects the cursor status and would only activate the script if the cursor is neutral or hovering text, or at least does not activate when hovering links, however I know no such software)
- Pressing middle mouse again to stop scrolling does not work (you can press any other mouse button to stop scrolling instead however, like left or right click, so it's no big deal really) this can probably be solved by fiddling with the script a little bit but I didn't get around to it.
- Scrolling is not bound to the cursor's starting position, rather the cursor itself (this is not an issue when holding down the button). What this means, is lets say you're in a browser and you use this autoscrolling script, if you move the mouse too high up the screen, instead of scrolling up and down on the current page you will start scrolling through your tabs instead, which is less than ideal for sure as it means you must be careful of where you move your cursor while scrolling.
The first issue can sort of be solved by configuring ./.config/.sxhkd/sxhkdrc like this
@button2
"/path/to/autoscroll"
However not only does this break your ability to hold-to-scroll, your middle mouse button will only function for autoscrolling, you will not be able to use the middle mouse button to open links in new tabs anymore without the ~button2 line. If you never use that functionality and never use middle mouse to paste things, this may suit you fine, but otherwise I'd advise against it.
The bottom line is, it works great for holding middle mouse to autoscroll, and it works not well at all for clicking to toggle autoscroll (which is why I left it disabled)
This satisfies my needs as requested by the OP however I will be waiting for a while for better answers if anyone happens to have a better solution before I mark this answer as the solution.
add a comment |
(The script here has been improved quite a lot by other users, I recommend using the version in Azerothian's answer instead.)
I have a working solution in the form of a bash script, it's not really perfect but it gets the job done, at least for my purposes.
The script requires xdotool and xinput and xsel. sxhkd is the recommended solution for binding the script to middle-mouse.
(Note: the script is dash compatible, change #!/bin/bash to #!/bin/dash to use the faster interpreter if it is installed)
#!/bin/bash
#Autoscroll (hold only)
echo -n | xsel -n -i
eval $(xdotool getmouselocation --shell)
starty=$Y
mouseid=$(xinput --list | grep -i -m 1 'mouse' | grep -o 'id=[0-9]+' | grep -o '[0-9]+')
toggle=0
while [ $toggle -eq 0 ]
do
sleep 0.02
mmouse=$(xinput --query-state $mouseid | grep 'button[2' | cut -d = -f2)
toggle=$(xinput --query-state $mouseid | grep 'button[2' | grep -c up)
eval $(xdotool getmouselocation --shell)
curry=$Y
#Scroll down
while [ $curry -gt $starty ] && [ $toggle -eq 0 ]
do
eval $(xdotool getmouselocation --shell)
curry=$Y
speed=$(expr $curry / 100 - $starty / 100)
xdotool click --repeat $speed --delay 1 5
toggle=$(xinput --query-state $mouseid | grep 'button[2' | grep -c up)
sleep 0.02
done
#Scroll up
while [ $curry -lt $starty ] && [ $toggle -eq 0 ]
do
eval $(xdotool getmouselocation --shell)
curry=$Y
speed=$(expr $curry / 100 - $starty / 100 | sed 's:-::')
xdotool click --repeat $speed --delay 1 4
toggle=$(xinput --query-state $mouseid | grep 'button[2' | grep -c up)
sleep 0.02
done
done
And here's the sxhkd configuration: ./.config/.sxhkd/sxhkdrc
~button2
"/path/to/autoscroll"
@button2
~control + c
echo -n | xsel -n -i
~control + shift + c
echo -n | xsel -n -i
~control + x
echo -n | xsel -n -i
The above script when triggered by sxhkd will allow for system-wide autoscrolling, but only when the middle mouse button is held. Clicking middle mouse will function as normal but with the pasting functionality disabled (except for circumstances where you do not use ctrl+c or ctrl+x to copy things).
If you prefer to leave middle click pasting enabled (not recommended, unless you like accidentally pasting things), use this instead:
~button2
"/path/to/autoscroll"
@button2
And also comment out or remove the first line of the autoscroll script (echo -n | xsel -n -i line)
There are a few reasons why I use sxhkd and not xbindkeys.
- sxhkd allows you to make the click for the bound button go through normally first before triggering the script (this is what ~button2 does), this enables the middle mouse button to maintain it's prior functionality alongside with executing this script.
- For some reason for both sxhkd and xbindkeys, if I tried to bind the script to middle mouse it would only work if the libinput mousewheel emulation is turned on, if I turn it off, the script simply won't run through these programs (even if it works fine on it's own) in short, the solution to this was sxhkd's @ prefix, hence @button2.
The good news is that holding down middle mouse to scroll works flawlessly (as long as you are ok with not being able to paste things with middle mouse).
The bad news is that clicking middle mouse to toggle auto-scrolling has some quite serious issues which is why I did not leave it in the default script.
In order to enable clicking to toggle autoscrolling replace all instances of:
toggle=$(xinput --query-state $mouseid | grep 'button[2' | grep -c up)
With:
if [ "$mmouse" = "down" ]; then
toggle=$(xinput --query-state $mouseid | grep 'button[2' | grep -c up)
else
toggle=$(xinput --query-state $mouseid | grep 'button[' | sort | grep -c down)
fi
Issues with both holding and clicking to scroll:
- It scrolls rather fast at minimum speed, while probably appropriate for most users, I personally would prefer slower speeds. The most likely solution for this is lowering the scrolling speed for libinput, this is sadly not as easy as it should be (hence not yet tested by me).
- Horizontal scrolling is not implemented, however it would be easy to implement (I just never use it so I had no reason to). Currently the entire script is based around the Y axis, copying what is already here and including the X axis would be a simple matter, and instead of mouse button 4 and 5 which are for vertical scrolling, you would use mouse button 6 and 7 for horizontal scrolling. (Fixed in Azerothian's version)
- There is no icon to indicate the starting position of the scrolling, and there is no cursor change to indicate that scrolling is active. I assume this shouldn't be that hard to solve, but I have assumed wrong before...
- If your mouse cursor is at a scrollable location (like your browser tabs, or your taskbar, where you can scroll between tasks/tabs) when you release the button, it will scroll.
Issues with clicking to scroll:
- Does not always trigger (this is a fault of sxhkd's current configuration, if I only use @button2 for the script and omit ~button2, it works perfectly fine, however, it would also mean that you could no longer use middle mouse to say open links in a new tab in a browser because the click would no longer be forwarded through)
- Does not detect when middle click was actually used for something else. (e.g. if you use middle click to open a link in a new tab, scrolling is most likely going to be activated as a side effect of that middle click, a possible solution would be having a program that detects the cursor status and would only activate the script if the cursor is neutral or hovering text, or at least does not activate when hovering links, however I know no such software)
- Pressing middle mouse again to stop scrolling does not work (you can press any other mouse button to stop scrolling instead however, like left or right click, so it's no big deal really) this can probably be solved by fiddling with the script a little bit but I didn't get around to it.
- Scrolling is not bound to the cursor's starting position, rather the cursor itself (this is not an issue when holding down the button). What this means, is lets say you're in a browser and you use this autoscrolling script, if you move the mouse too high up the screen, instead of scrolling up and down on the current page you will start scrolling through your tabs instead, which is less than ideal for sure as it means you must be careful of where you move your cursor while scrolling.
The first issue can sort of be solved by configuring ./.config/.sxhkd/sxhkdrc like this
@button2
"/path/to/autoscroll"
However not only does this break your ability to hold-to-scroll, your middle mouse button will only function for autoscrolling, you will not be able to use the middle mouse button to open links in new tabs anymore without the ~button2 line. If you never use that functionality and never use middle mouse to paste things, this may suit you fine, but otherwise I'd advise against it.
The bottom line is, it works great for holding middle mouse to autoscroll, and it works not well at all for clicking to toggle autoscroll (which is why I left it disabled)
This satisfies my needs as requested by the OP however I will be waiting for a while for better answers if anyone happens to have a better solution before I mark this answer as the solution.
add a comment |
(The script here has been improved quite a lot by other users, I recommend using the version in Azerothian's answer instead.)
I have a working solution in the form of a bash script, it's not really perfect but it gets the job done, at least for my purposes.
The script requires xdotool and xinput and xsel. sxhkd is the recommended solution for binding the script to middle-mouse.
(Note: the script is dash compatible, change #!/bin/bash to #!/bin/dash to use the faster interpreter if it is installed)
#!/bin/bash
#Autoscroll (hold only)
echo -n | xsel -n -i
eval $(xdotool getmouselocation --shell)
starty=$Y
mouseid=$(xinput --list | grep -i -m 1 'mouse' | grep -o 'id=[0-9]+' | grep -o '[0-9]+')
toggle=0
while [ $toggle -eq 0 ]
do
sleep 0.02
mmouse=$(xinput --query-state $mouseid | grep 'button[2' | cut -d = -f2)
toggle=$(xinput --query-state $mouseid | grep 'button[2' | grep -c up)
eval $(xdotool getmouselocation --shell)
curry=$Y
#Scroll down
while [ $curry -gt $starty ] && [ $toggle -eq 0 ]
do
eval $(xdotool getmouselocation --shell)
curry=$Y
speed=$(expr $curry / 100 - $starty / 100)
xdotool click --repeat $speed --delay 1 5
toggle=$(xinput --query-state $mouseid | grep 'button[2' | grep -c up)
sleep 0.02
done
#Scroll up
while [ $curry -lt $starty ] && [ $toggle -eq 0 ]
do
eval $(xdotool getmouselocation --shell)
curry=$Y
speed=$(expr $curry / 100 - $starty / 100 | sed 's:-::')
xdotool click --repeat $speed --delay 1 4
toggle=$(xinput --query-state $mouseid | grep 'button[2' | grep -c up)
sleep 0.02
done
done
And here's the sxhkd configuration: ./.config/.sxhkd/sxhkdrc
~button2
"/path/to/autoscroll"
@button2
~control + c
echo -n | xsel -n -i
~control + shift + c
echo -n | xsel -n -i
~control + x
echo -n | xsel -n -i
The above script when triggered by sxhkd will allow for system-wide autoscrolling, but only when the middle mouse button is held. Clicking middle mouse will function as normal but with the pasting functionality disabled (except for circumstances where you do not use ctrl+c or ctrl+x to copy things).
If you prefer to leave middle click pasting enabled (not recommended, unless you like accidentally pasting things), use this instead:
~button2
"/path/to/autoscroll"
@button2
And also comment out or remove the first line of the autoscroll script (echo -n | xsel -n -i line)
There are a few reasons why I use sxhkd and not xbindkeys.
- sxhkd allows you to make the click for the bound button go through normally first before triggering the script (this is what ~button2 does), this enables the middle mouse button to maintain it's prior functionality alongside with executing this script.
- For some reason for both sxhkd and xbindkeys, if I tried to bind the script to middle mouse it would only work if the libinput mousewheel emulation is turned on, if I turn it off, the script simply won't run through these programs (even if it works fine on it's own) in short, the solution to this was sxhkd's @ prefix, hence @button2.
The good news is that holding down middle mouse to scroll works flawlessly (as long as you are ok with not being able to paste things with middle mouse).
The bad news is that clicking middle mouse to toggle auto-scrolling has some quite serious issues which is why I did not leave it in the default script.
In order to enable clicking to toggle autoscrolling replace all instances of:
toggle=$(xinput --query-state $mouseid | grep 'button[2' | grep -c up)
With:
if [ "$mmouse" = "down" ]; then
toggle=$(xinput --query-state $mouseid | grep 'button[2' | grep -c up)
else
toggle=$(xinput --query-state $mouseid | grep 'button[' | sort | grep -c down)
fi
Issues with both holding and clicking to scroll:
- It scrolls rather fast at minimum speed, while probably appropriate for most users, I personally would prefer slower speeds. The most likely solution for this is lowering the scrolling speed for libinput, this is sadly not as easy as it should be (hence not yet tested by me).
- Horizontal scrolling is not implemented, however it would be easy to implement (I just never use it so I had no reason to). Currently the entire script is based around the Y axis, copying what is already here and including the X axis would be a simple matter, and instead of mouse button 4 and 5 which are for vertical scrolling, you would use mouse button 6 and 7 for horizontal scrolling. (Fixed in Azerothian's version)
- There is no icon to indicate the starting position of the scrolling, and there is no cursor change to indicate that scrolling is active. I assume this shouldn't be that hard to solve, but I have assumed wrong before...
- If your mouse cursor is at a scrollable location (like your browser tabs, or your taskbar, where you can scroll between tasks/tabs) when you release the button, it will scroll.
Issues with clicking to scroll:
- Does not always trigger (this is a fault of sxhkd's current configuration, if I only use @button2 for the script and omit ~button2, it works perfectly fine, however, it would also mean that you could no longer use middle mouse to say open links in a new tab in a browser because the click would no longer be forwarded through)
- Does not detect when middle click was actually used for something else. (e.g. if you use middle click to open a link in a new tab, scrolling is most likely going to be activated as a side effect of that middle click, a possible solution would be having a program that detects the cursor status and would only activate the script if the cursor is neutral or hovering text, or at least does not activate when hovering links, however I know no such software)
- Pressing middle mouse again to stop scrolling does not work (you can press any other mouse button to stop scrolling instead however, like left or right click, so it's no big deal really) this can probably be solved by fiddling with the script a little bit but I didn't get around to it.
- Scrolling is not bound to the cursor's starting position, rather the cursor itself (this is not an issue when holding down the button). What this means, is lets say you're in a browser and you use this autoscrolling script, if you move the mouse too high up the screen, instead of scrolling up and down on the current page you will start scrolling through your tabs instead, which is less than ideal for sure as it means you must be careful of where you move your cursor while scrolling.
The first issue can sort of be solved by configuring ./.config/.sxhkd/sxhkdrc like this
@button2
"/path/to/autoscroll"
However not only does this break your ability to hold-to-scroll, your middle mouse button will only function for autoscrolling, you will not be able to use the middle mouse button to open links in new tabs anymore without the ~button2 line. If you never use that functionality and never use middle mouse to paste things, this may suit you fine, but otherwise I'd advise against it.
The bottom line is, it works great for holding middle mouse to autoscroll, and it works not well at all for clicking to toggle autoscroll (which is why I left it disabled)
This satisfies my needs as requested by the OP however I will be waiting for a while for better answers if anyone happens to have a better solution before I mark this answer as the solution.
(The script here has been improved quite a lot by other users, I recommend using the version in Azerothian's answer instead.)
I have a working solution in the form of a bash script, it's not really perfect but it gets the job done, at least for my purposes.
The script requires xdotool and xinput and xsel. sxhkd is the recommended solution for binding the script to middle-mouse.
(Note: the script is dash compatible, change #!/bin/bash to #!/bin/dash to use the faster interpreter if it is installed)
#!/bin/bash
#Autoscroll (hold only)
echo -n | xsel -n -i
eval $(xdotool getmouselocation --shell)
starty=$Y
mouseid=$(xinput --list | grep -i -m 1 'mouse' | grep -o 'id=[0-9]+' | grep -o '[0-9]+')
toggle=0
while [ $toggle -eq 0 ]
do
sleep 0.02
mmouse=$(xinput --query-state $mouseid | grep 'button[2' | cut -d = -f2)
toggle=$(xinput --query-state $mouseid | grep 'button[2' | grep -c up)
eval $(xdotool getmouselocation --shell)
curry=$Y
#Scroll down
while [ $curry -gt $starty ] && [ $toggle -eq 0 ]
do
eval $(xdotool getmouselocation --shell)
curry=$Y
speed=$(expr $curry / 100 - $starty / 100)
xdotool click --repeat $speed --delay 1 5
toggle=$(xinput --query-state $mouseid | grep 'button[2' | grep -c up)
sleep 0.02
done
#Scroll up
while [ $curry -lt $starty ] && [ $toggle -eq 0 ]
do
eval $(xdotool getmouselocation --shell)
curry=$Y
speed=$(expr $curry / 100 - $starty / 100 | sed 's:-::')
xdotool click --repeat $speed --delay 1 4
toggle=$(xinput --query-state $mouseid | grep 'button[2' | grep -c up)
sleep 0.02
done
done
And here's the sxhkd configuration: ./.config/.sxhkd/sxhkdrc
~button2
"/path/to/autoscroll"
@button2
~control + c
echo -n | xsel -n -i
~control + shift + c
echo -n | xsel -n -i
~control + x
echo -n | xsel -n -i
The above script when triggered by sxhkd will allow for system-wide autoscrolling, but only when the middle mouse button is held. Clicking middle mouse will function as normal but with the pasting functionality disabled (except for circumstances where you do not use ctrl+c or ctrl+x to copy things).
If you prefer to leave middle click pasting enabled (not recommended, unless you like accidentally pasting things), use this instead:
~button2
"/path/to/autoscroll"
@button2
And also comment out or remove the first line of the autoscroll script (echo -n | xsel -n -i line)
There are a few reasons why I use sxhkd and not xbindkeys.
- sxhkd allows you to make the click for the bound button go through normally first before triggering the script (this is what ~button2 does), this enables the middle mouse button to maintain it's prior functionality alongside with executing this script.
- For some reason for both sxhkd and xbindkeys, if I tried to bind the script to middle mouse it would only work if the libinput mousewheel emulation is turned on, if I turn it off, the script simply won't run through these programs (even if it works fine on it's own) in short, the solution to this was sxhkd's @ prefix, hence @button2.
The good news is that holding down middle mouse to scroll works flawlessly (as long as you are ok with not being able to paste things with middle mouse).
The bad news is that clicking middle mouse to toggle auto-scrolling has some quite serious issues which is why I did not leave it in the default script.
In order to enable clicking to toggle autoscrolling replace all instances of:
toggle=$(xinput --query-state $mouseid | grep 'button[2' | grep -c up)
With:
if [ "$mmouse" = "down" ]; then
toggle=$(xinput --query-state $mouseid | grep 'button[2' | grep -c up)
else
toggle=$(xinput --query-state $mouseid | grep 'button[' | sort | grep -c down)
fi
Issues with both holding and clicking to scroll:
- It scrolls rather fast at minimum speed, while probably appropriate for most users, I personally would prefer slower speeds. The most likely solution for this is lowering the scrolling speed for libinput, this is sadly not as easy as it should be (hence not yet tested by me).
- Horizontal scrolling is not implemented, however it would be easy to implement (I just never use it so I had no reason to). Currently the entire script is based around the Y axis, copying what is already here and including the X axis would be a simple matter, and instead of mouse button 4 and 5 which are for vertical scrolling, you would use mouse button 6 and 7 for horizontal scrolling. (Fixed in Azerothian's version)
- There is no icon to indicate the starting position of the scrolling, and there is no cursor change to indicate that scrolling is active. I assume this shouldn't be that hard to solve, but I have assumed wrong before...
- If your mouse cursor is at a scrollable location (like your browser tabs, or your taskbar, where you can scroll between tasks/tabs) when you release the button, it will scroll.
Issues with clicking to scroll:
- Does not always trigger (this is a fault of sxhkd's current configuration, if I only use @button2 for the script and omit ~button2, it works perfectly fine, however, it would also mean that you could no longer use middle mouse to say open links in a new tab in a browser because the click would no longer be forwarded through)
- Does not detect when middle click was actually used for something else. (e.g. if you use middle click to open a link in a new tab, scrolling is most likely going to be activated as a side effect of that middle click, a possible solution would be having a program that detects the cursor status and would only activate the script if the cursor is neutral or hovering text, or at least does not activate when hovering links, however I know no such software)
- Pressing middle mouse again to stop scrolling does not work (you can press any other mouse button to stop scrolling instead however, like left or right click, so it's no big deal really) this can probably be solved by fiddling with the script a little bit but I didn't get around to it.
- Scrolling is not bound to the cursor's starting position, rather the cursor itself (this is not an issue when holding down the button). What this means, is lets say you're in a browser and you use this autoscrolling script, if you move the mouse too high up the screen, instead of scrolling up and down on the current page you will start scrolling through your tabs instead, which is less than ideal for sure as it means you must be careful of where you move your cursor while scrolling.
The first issue can sort of be solved by configuring ./.config/.sxhkd/sxhkdrc like this
@button2
"/path/to/autoscroll"
However not only does this break your ability to hold-to-scroll, your middle mouse button will only function for autoscrolling, you will not be able to use the middle mouse button to open links in new tabs anymore without the ~button2 line. If you never use that functionality and never use middle mouse to paste things, this may suit you fine, but otherwise I'd advise against it.
The bottom line is, it works great for holding middle mouse to autoscroll, and it works not well at all for clicking to toggle autoscroll (which is why I left it disabled)
This satisfies my needs as requested by the OP however I will be waiting for a while for better answers if anyone happens to have a better solution before I mark this answer as the solution.
edited 2 days ago
answered Sep 30 '18 at 19:35
CestarianCestarian
90411527
90411527
add a comment |
add a comment |
I don't have a better answer outside that i have improved (in my opinion) the script cestarian provided, I wanted the horizontal scroll, and I also had issues with my Logitech mouse not being picked up correctly.
I also didn't see the reason as to having so many loops where a single loop will be much faster and allows for multi direction scrolling on the same cycle :D
Tested on xUbuntu 18.04.2 LTS
sudo apt install xdotool xsel sxhkd
~/.config/sxkhd/sxhkdrc
~button2
"~/.config/sxkhd/autoscroll.sh"
@button2
~control + c
echo -n | xsel -n -i
~control + shift + c
echo -n | xsel -n -i
~control + x
echo -n | xsel -n -i
~/.config/sxkhd/autoscroll.sh
#!/bin/dash
# Autoscroll (hold only)
middlemousebutton=2
mousescrollup=4
mousescrolldown=5
mousescrollleft=6
mousescrollright=7
enableverticalscroll=1
enablehorizontalscroll=1
## Danger below :D
echo -n | xsel -n -i
eval $(xdotool getmouselocation --shell)
starty=$Y
startx=$X
toggle=$middlemousebutton
while [ $toggle -eq $middlemousebutton ]
do
eval $(xdotool getmouselocation --shell)
curry=$Y
currx=$X
if [ $enableverticalscroll -eq 1 ]
then
if [ $curry -gt $starty ]
then
speedy=$(expr $curry / 100 - $starty / 100)
if [ $speedy -gt 0 ]
then
xdotool click --repeat $speedy --delay 1 $mousescrolldown
fi
else
speedy=$(expr $curry / 100 - $starty / 100 | sed 's:-::')
if [ $speedy -gt 0 ]
then
xdotool click --repeat $speedy --delay 1 $mousescrollup
fi
fi
fi
if [ $enablehorizontalscroll -eq 1 ]
then
if [ $currx -gt $startx ]
then
speedx=$(expr $currx / 100 - $startx / 100)
if [ $speedx -gt 0 ]
then
xdotool click --repeat $speedx --delay 1 $mousescrollright
fi
else
speedx=$(expr $currx / 100 - $startx / 100 | sed 's:-::')
if [ $speedx -gt 0 ]
then
xdotool click --repeat $speedx --delay 1 $mousescrollleft
fi
fi
fi
toggle=$(xinput --list "Virtual core pointer" | grep -i -m 1 "Button state:" | grep -o "[$middlemousebutton]+")
sleep 0.02
done
chmod +x ~/.config/sxkhd/autoscroll.sh
Make sure you add sxhkd to Session and Startup -> Autostart Applications
and everything should work on next boot
New contributor
Nice, I wanted horizontal scrolling too but was too lazy to implement it. Also that defaultstate thing, I don't even remember how that was supposed to work (messy little script isn't it?...), but setting it to 1 fixed it on my other mouse, your script definitely is nicer. My defaultstate should have been 2 though according to how I'm supposed to find it out, but it only works if set to 1.
– Cestarian
2 days ago
good point on the getting the state, i made a mistake in regards to defaultstate, i have updated the above to reflect its actual purpose. it is now activestate and i updated the instructions to match ^^
– Azerothian
yesterday
1
I just had epiphany!!! we don't need to use the target mouse to check for the state of the mouse button, i found that we can look at the button state in the virtual core pointer, if 2 then middle mouse button is pressed. solves the issue when switching between two different mice. i have updated the script with my current solution.
– Azerothian
yesterday
add a comment |
I don't have a better answer outside that i have improved (in my opinion) the script cestarian provided, I wanted the horizontal scroll, and I also had issues with my Logitech mouse not being picked up correctly.
I also didn't see the reason as to having so many loops where a single loop will be much faster and allows for multi direction scrolling on the same cycle :D
Tested on xUbuntu 18.04.2 LTS
sudo apt install xdotool xsel sxhkd
~/.config/sxkhd/sxhkdrc
~button2
"~/.config/sxkhd/autoscroll.sh"
@button2
~control + c
echo -n | xsel -n -i
~control + shift + c
echo -n | xsel -n -i
~control + x
echo -n | xsel -n -i
~/.config/sxkhd/autoscroll.sh
#!/bin/dash
# Autoscroll (hold only)
middlemousebutton=2
mousescrollup=4
mousescrolldown=5
mousescrollleft=6
mousescrollright=7
enableverticalscroll=1
enablehorizontalscroll=1
## Danger below :D
echo -n | xsel -n -i
eval $(xdotool getmouselocation --shell)
starty=$Y
startx=$X
toggle=$middlemousebutton
while [ $toggle -eq $middlemousebutton ]
do
eval $(xdotool getmouselocation --shell)
curry=$Y
currx=$X
if [ $enableverticalscroll -eq 1 ]
then
if [ $curry -gt $starty ]
then
speedy=$(expr $curry / 100 - $starty / 100)
if [ $speedy -gt 0 ]
then
xdotool click --repeat $speedy --delay 1 $mousescrolldown
fi
else
speedy=$(expr $curry / 100 - $starty / 100 | sed 's:-::')
if [ $speedy -gt 0 ]
then
xdotool click --repeat $speedy --delay 1 $mousescrollup
fi
fi
fi
if [ $enablehorizontalscroll -eq 1 ]
then
if [ $currx -gt $startx ]
then
speedx=$(expr $currx / 100 - $startx / 100)
if [ $speedx -gt 0 ]
then
xdotool click --repeat $speedx --delay 1 $mousescrollright
fi
else
speedx=$(expr $currx / 100 - $startx / 100 | sed 's:-::')
if [ $speedx -gt 0 ]
then
xdotool click --repeat $speedx --delay 1 $mousescrollleft
fi
fi
fi
toggle=$(xinput --list "Virtual core pointer" | grep -i -m 1 "Button state:" | grep -o "[$middlemousebutton]+")
sleep 0.02
done
chmod +x ~/.config/sxkhd/autoscroll.sh
Make sure you add sxhkd to Session and Startup -> Autostart Applications
and everything should work on next boot
New contributor
Nice, I wanted horizontal scrolling too but was too lazy to implement it. Also that defaultstate thing, I don't even remember how that was supposed to work (messy little script isn't it?...), but setting it to 1 fixed it on my other mouse, your script definitely is nicer. My defaultstate should have been 2 though according to how I'm supposed to find it out, but it only works if set to 1.
– Cestarian
2 days ago
good point on the getting the state, i made a mistake in regards to defaultstate, i have updated the above to reflect its actual purpose. it is now activestate and i updated the instructions to match ^^
– Azerothian
yesterday
1
I just had epiphany!!! we don't need to use the target mouse to check for the state of the mouse button, i found that we can look at the button state in the virtual core pointer, if 2 then middle mouse button is pressed. solves the issue when switching between two different mice. i have updated the script with my current solution.
– Azerothian
yesterday
add a comment |
I don't have a better answer outside that i have improved (in my opinion) the script cestarian provided, I wanted the horizontal scroll, and I also had issues with my Logitech mouse not being picked up correctly.
I also didn't see the reason as to having so many loops where a single loop will be much faster and allows for multi direction scrolling on the same cycle :D
Tested on xUbuntu 18.04.2 LTS
sudo apt install xdotool xsel sxhkd
~/.config/sxkhd/sxhkdrc
~button2
"~/.config/sxkhd/autoscroll.sh"
@button2
~control + c
echo -n | xsel -n -i
~control + shift + c
echo -n | xsel -n -i
~control + x
echo -n | xsel -n -i
~/.config/sxkhd/autoscroll.sh
#!/bin/dash
# Autoscroll (hold only)
middlemousebutton=2
mousescrollup=4
mousescrolldown=5
mousescrollleft=6
mousescrollright=7
enableverticalscroll=1
enablehorizontalscroll=1
## Danger below :D
echo -n | xsel -n -i
eval $(xdotool getmouselocation --shell)
starty=$Y
startx=$X
toggle=$middlemousebutton
while [ $toggle -eq $middlemousebutton ]
do
eval $(xdotool getmouselocation --shell)
curry=$Y
currx=$X
if [ $enableverticalscroll -eq 1 ]
then
if [ $curry -gt $starty ]
then
speedy=$(expr $curry / 100 - $starty / 100)
if [ $speedy -gt 0 ]
then
xdotool click --repeat $speedy --delay 1 $mousescrolldown
fi
else
speedy=$(expr $curry / 100 - $starty / 100 | sed 's:-::')
if [ $speedy -gt 0 ]
then
xdotool click --repeat $speedy --delay 1 $mousescrollup
fi
fi
fi
if [ $enablehorizontalscroll -eq 1 ]
then
if [ $currx -gt $startx ]
then
speedx=$(expr $currx / 100 - $startx / 100)
if [ $speedx -gt 0 ]
then
xdotool click --repeat $speedx --delay 1 $mousescrollright
fi
else
speedx=$(expr $currx / 100 - $startx / 100 | sed 's:-::')
if [ $speedx -gt 0 ]
then
xdotool click --repeat $speedx --delay 1 $mousescrollleft
fi
fi
fi
toggle=$(xinput --list "Virtual core pointer" | grep -i -m 1 "Button state:" | grep -o "[$middlemousebutton]+")
sleep 0.02
done
chmod +x ~/.config/sxkhd/autoscroll.sh
Make sure you add sxhkd to Session and Startup -> Autostart Applications
and everything should work on next boot
New contributor
I don't have a better answer outside that i have improved (in my opinion) the script cestarian provided, I wanted the horizontal scroll, and I also had issues with my Logitech mouse not being picked up correctly.
I also didn't see the reason as to having so many loops where a single loop will be much faster and allows for multi direction scrolling on the same cycle :D
Tested on xUbuntu 18.04.2 LTS
sudo apt install xdotool xsel sxhkd
~/.config/sxkhd/sxhkdrc
~button2
"~/.config/sxkhd/autoscroll.sh"
@button2
~control + c
echo -n | xsel -n -i
~control + shift + c
echo -n | xsel -n -i
~control + x
echo -n | xsel -n -i
~/.config/sxkhd/autoscroll.sh
#!/bin/dash
# Autoscroll (hold only)
middlemousebutton=2
mousescrollup=4
mousescrolldown=5
mousescrollleft=6
mousescrollright=7
enableverticalscroll=1
enablehorizontalscroll=1
## Danger below :D
echo -n | xsel -n -i
eval $(xdotool getmouselocation --shell)
starty=$Y
startx=$X
toggle=$middlemousebutton
while [ $toggle -eq $middlemousebutton ]
do
eval $(xdotool getmouselocation --shell)
curry=$Y
currx=$X
if [ $enableverticalscroll -eq 1 ]
then
if [ $curry -gt $starty ]
then
speedy=$(expr $curry / 100 - $starty / 100)
if [ $speedy -gt 0 ]
then
xdotool click --repeat $speedy --delay 1 $mousescrolldown
fi
else
speedy=$(expr $curry / 100 - $starty / 100 | sed 's:-::')
if [ $speedy -gt 0 ]
then
xdotool click --repeat $speedy --delay 1 $mousescrollup
fi
fi
fi
if [ $enablehorizontalscroll -eq 1 ]
then
if [ $currx -gt $startx ]
then
speedx=$(expr $currx / 100 - $startx / 100)
if [ $speedx -gt 0 ]
then
xdotool click --repeat $speedx --delay 1 $mousescrollright
fi
else
speedx=$(expr $currx / 100 - $startx / 100 | sed 's:-::')
if [ $speedx -gt 0 ]
then
xdotool click --repeat $speedx --delay 1 $mousescrollleft
fi
fi
fi
toggle=$(xinput --list "Virtual core pointer" | grep -i -m 1 "Button state:" | grep -o "[$middlemousebutton]+")
sleep 0.02
done
chmod +x ~/.config/sxkhd/autoscroll.sh
Make sure you add sxhkd to Session and Startup -> Autostart Applications
and everything should work on next boot
New contributor
edited yesterday
New contributor
answered May 26 at 6:19
AzerothianAzerothian
1114
1114
New contributor
New contributor
Nice, I wanted horizontal scrolling too but was too lazy to implement it. Also that defaultstate thing, I don't even remember how that was supposed to work (messy little script isn't it?...), but setting it to 1 fixed it on my other mouse, your script definitely is nicer. My defaultstate should have been 2 though according to how I'm supposed to find it out, but it only works if set to 1.
– Cestarian
2 days ago
good point on the getting the state, i made a mistake in regards to defaultstate, i have updated the above to reflect its actual purpose. it is now activestate and i updated the instructions to match ^^
– Azerothian
yesterday
1
I just had epiphany!!! we don't need to use the target mouse to check for the state of the mouse button, i found that we can look at the button state in the virtual core pointer, if 2 then middle mouse button is pressed. solves the issue when switching between two different mice. i have updated the script with my current solution.
– Azerothian
yesterday
add a comment |
Nice, I wanted horizontal scrolling too but was too lazy to implement it. Also that defaultstate thing, I don't even remember how that was supposed to work (messy little script isn't it?...), but setting it to 1 fixed it on my other mouse, your script definitely is nicer. My defaultstate should have been 2 though according to how I'm supposed to find it out, but it only works if set to 1.
– Cestarian
2 days ago
good point on the getting the state, i made a mistake in regards to defaultstate, i have updated the above to reflect its actual purpose. it is now activestate and i updated the instructions to match ^^
– Azerothian
yesterday
1
I just had epiphany!!! we don't need to use the target mouse to check for the state of the mouse button, i found that we can look at the button state in the virtual core pointer, if 2 then middle mouse button is pressed. solves the issue when switching between two different mice. i have updated the script with my current solution.
– Azerothian
yesterday
Nice, I wanted horizontal scrolling too but was too lazy to implement it. Also that defaultstate thing, I don't even remember how that was supposed to work (messy little script isn't it?...), but setting it to 1 fixed it on my other mouse, your script definitely is nicer. My defaultstate should have been 2 though according to how I'm supposed to find it out, but it only works if set to 1.
– Cestarian
2 days ago
Nice, I wanted horizontal scrolling too but was too lazy to implement it. Also that defaultstate thing, I don't even remember how that was supposed to work (messy little script isn't it?...), but setting it to 1 fixed it on my other mouse, your script definitely is nicer. My defaultstate should have been 2 though according to how I'm supposed to find it out, but it only works if set to 1.
– Cestarian
2 days ago
good point on the getting the state, i made a mistake in regards to defaultstate, i have updated the above to reflect its actual purpose. it is now activestate and i updated the instructions to match ^^
– Azerothian
yesterday
good point on the getting the state, i made a mistake in regards to defaultstate, i have updated the above to reflect its actual purpose. it is now activestate and i updated the instructions to match ^^
– Azerothian
yesterday
1
1
I just had epiphany!!! we don't need to use the target mouse to check for the state of the mouse button, i found that we can look at the button state in the virtual core pointer, if 2 then middle mouse button is pressed. solves the issue when switching between two different mice. i have updated the script with my current solution.
– Azerothian
yesterday
I just had epiphany!!! we don't need to use the target mouse to check for the state of the mouse button, i found that we can look at the button state in the virtual core pointer, if 2 then middle mouse button is pressed. solves the issue when switching between two different mice. i have updated the script with my current solution.
– Azerothian
yesterday
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f472398%2fcan-i-make-middle-mouse-scrolling-on-linux-behave-more-like-autoscrolling-on-win%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown