Skip to content

Commit 817f1a7

Browse files
committed
split BUTTON into BUTTON_START and BUTTON_STOP
1 parent fbc26bd commit 817f1a7

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ chmod u+x autoscroll.py
2727

2828
## Configuration
2929

30-
You can adjust the `DELAY` and `BUTTON` constants for better experience.
30+
You can adjust the `DELAY`, `BUTTON_START` and `BUTTON_STOP` constants for better experience.
3131

3232
By changing `DELAY` you can adjust the speed of scrolling. By default its value is 5 but you may find it either too fast or too slow. You can decrease the value to make scrolling faster or increase it to make scrolling slower.
3333

34-
Modifying `BUTTON` is going to change the button used for entering the scroll mode. The default is the middle mouse button but if your mouse has additional side buttons it might be a good idea to use one of them instead, as the middle button is often used for different purposes (for example to open a link in a new tab in most web browsers or to copy and paste text system-wide). As the script is using the pynput library, you can hopefully find names of all of your mouse buttons with the following piece of code:
34+
Modifying `BUTTON_START` and `BUTTON_STOP` is going to change the button used for entering and exiting the scroll mode. The default for both is the middle mouse button but if your mouse has additional side buttons it might be a good idea to use them instead, as the middle button is often used for different purposes (for example to open a link in a new tab in most web browsers or to copy and paste text system-wide). As the script is using the pynput library, you can hopefully find names of all of your mouse buttons with the following piece of code:
3535
```python
3636
from pynput.mouse import Button, Listener
3737

@@ -47,6 +47,6 @@ with Listener(on_click = on_click) as listener:
4747

4848
## Usage
4949

50-
Click the middle mouse button (or the button you have assigned to `BUTTON`) and move your mouse to start scrolling. The further you move the mouse (vertically) from the point where you clicked the button, the faster the scrolling becomes. To leave the scroll mode, simply press the button again.
50+
Click the middle mouse button (or the button you assigned to `BUTTON_START`) and move your mouse to start scrolling. The further you move the mouse (vertically) from the point where you have clicked the button, the faster the scrolling becomes. To leave the scroll mode, simply press the middle mouse button again (or press the button you assigned to `BUTTON_STOP`).
5151

5252
Note that at slow speed the scrolling is not smooth and (probably) there is no way to make it smooth. However, one can easily get used to it.

autoscroll.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,14 @@ def on_move(x, y):
1818
interval = DELAY / abs(delta)
1919

2020
def on_click(x, y, button, pressed):
21-
global pos, scroll_mode, direction, interval, BUTTON
22-
if button == BUTTON and pressed:
23-
if scroll_mode.is_set():
24-
scroll_mode.clear()
25-
else:
26-
pos = (x, y)
27-
direction = 0
28-
interval = 0
29-
scroll_mode.set()
21+
global pos, scroll_mode, direction, interval, BUTTON_START, BUTTON_STOP
22+
if button == BUTTON_START and pressed and not scroll_mode.is_set():
23+
pos = (x, y)
24+
direction = 0
25+
interval = 0
26+
scroll_mode.set()
27+
elif button == BUTTON_STOP and pressed and scroll_mode.is_set():
28+
scroll_mode.clear()
3029

3130
def autoscroll():
3231
global mouse, scroll_mode, direction, interval
@@ -45,7 +44,9 @@ def autoscroll():
4544
# modify this to adjust the speed of scrolling
4645
DELAY = 5
4746
# modify this to change the button used for entering the scroll mode
48-
BUTTON = Button.middle
47+
BUTTON_START = Button.middle
48+
# modify this to change the button used for exiting the scroll mode
49+
BUTTON_STOP = Button.middle
4950

5051
listener.start()
5152
autoscroll()

0 commit comments

Comments
 (0)