forked from sean-nicholas/scroll-windows-v-desktops
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscroll-desktops.py
39 lines (31 loc) · 905 Bytes
/
scroll-desktops.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from pynput import mouse
from pynput.keyboard import Key, Controller
import json
from pathlib import Path
from sys import argv
config_file = argv[1]
config_path = Path(config_file)
with open(config_path, 'r') as f:
config = json.load(f)
keyboard = Controller()
def on_scroll(x, y, dx, dy):
if (x > config['xMin'] and x < config['xMax'] and y > config['yMin'] and y < config['yMax']):
keyboard.press(Key.cmd)
keyboard.press(Key.ctrl)
if dy < 0:
keyboard.press(Key.right)
else:
keyboard.press(Key.left)
keyboard.release(Key.cmd)
keyboard.release(Key.ctrl)
if dy < 0:
keyboard.release(Key.right)
else:
keyboard.release(Key.left)
if (config['printPosition'] == True):
print('Scrolled {0} at {1}'.format(
'down' if dy < 0 else 'up',
(x, y)))
with mouse.Listener(
on_scroll=on_scroll) as listener:
listener.join()