Created
April 23, 2020 20:20
-
-
Save sean-nicholas/55485c3a94ff38b5e37a577904f611b5 to your computer and use it in GitHub Desktop.
Scroll virtual desktops in windows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from pynput import mouse | |
| from pynput.keyboard import Key, Controller | |
| import json | |
| with open('config.json', '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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment