Skip to content

Commit 0241d0f

Browse files
committed
added dead area
1 parent 817f1a7 commit 0241d0f

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

README.md

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

2828
## Configuration
2929

30-
You can adjust the `DELAY`, `BUTTON_START` and `BUTTON_STOP` constants for better experience.
30+
You can adjust the `DELAY`, `BUTTON_START`, `BUTTON_STOP` and `DEAD_AREA` 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

@@ -44,6 +44,8 @@ def on_click(x, y, button, pressed):
4444
with Listener(on_click = on_click) as listener:
4545
listener.join()
4646
```
47+
\
48+
By default the scrolling begins when the mouse pointer is 30 px below or above the point where `BUTTON_START` was pressed. In order to change that you can modify `DEAD_AREA`. If you set it to 0 (which is the minimum value), the scrolling will be paused only when the vertical position of the cursor is exactly the same as the position in which the scroll mode was activated.
4749

4850
## Usage
4951

autoscroll.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
from time import sleep
44

55
def on_move(x, y):
6-
global pos, scroll_mode, direction, interval, DELAY
6+
global pos, scroll_mode, direction, interval, DELAY, DEAD_AREA
77
if scroll_mode.is_set():
88
delta = pos[1] - y
9-
if delta > 0:
9+
if abs(delta) <= DEAD_AREA:
10+
direction = 0
11+
elif delta > 0:
1012
direction = 1
1113
elif delta < 0:
1214
direction = -1
13-
else:
14-
direction = 0
15-
if abs(delta) < DELAY * 2:
15+
if abs(delta) <= DEAD_AREA + DELAY * 2:
1616
interval = 0.5
1717
else:
18-
interval = DELAY / abs(delta)
18+
interval = DELAY / (abs(delta) - DEAD_AREA)
1919

2020
def on_click(x, y, button, pressed):
2121
global pos, scroll_mode, direction, interval, BUTTON_START, BUTTON_STOP
@@ -47,6 +47,8 @@ def autoscroll():
4747
BUTTON_START = Button.middle
4848
# modify this to change the button used for exiting the scroll mode
4949
BUTTON_STOP = Button.middle
50+
# modify this to change the size (in px) of the area below and above the starting point where the scrolling is paused
51+
DEAD_AREA = 30
5052

5153
listener.start()
5254
autoscroll()

0 commit comments

Comments
 (0)