Last active
December 31, 2015 15:49
-
-
Save artizirk/8009004 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env python3 | |
####################### | |
# | |
# Auto scroll while holding down mouse side buttons | |
# | |
# | |
from pymouse import PyMouse | |
from pymouse import PyMouseEvent | |
import threading | |
from multiprocessing import Process, Queue | |
import time | |
def scroller(q): | |
m = PyMouse() | |
print("scroller is ready") | |
scroll_up = False | |
scroll_down = False | |
scroll_up_time = time.time() | |
scroll_down_time = time.time() | |
scroll_sleep_time = 0.1 | |
while True: | |
try: | |
d = q.get_nowait() | |
if d[0]=="up": | |
scroll_up = d[1] | |
scroll_up_time = time.time() | |
else: | |
scroll_down = d[1] | |
scroll_down_time = time.time() | |
except Exception as e: | |
#print(e) | |
pass | |
time.sleep(scroll_sleep_time) | |
if scroll_up: | |
m.scroll(vertical=1) | |
print("scrolling 1") | |
elif scroll_down: | |
m.scroll(vertical=-1) | |
print("scrolling -1") | |
if scroll_up or scroll_down: | |
if scroll_sleep_time > 0.04: | |
scroll_sleep_time -= 0.01 | |
else: | |
scroll_sleep_time = 0.1 | |
#print("nothing happening") | |
class Autoscroll(PyMouseEvent): | |
def __init__(self, q): | |
PyMouseEvent.__init__(self) | |
self.q = q | |
self.scroller = Process(target=scroller, args=(q,)) | |
#self.scroller.daemon = True | |
self.scroller.start() | |
def click(self, x, y, button, press): | |
print("x:{}, y:{}, button:{}, press:{}".format( | |
x, y, button, press)) | |
if button == 10: | |
q.put(("up", press)) | |
elif button == 11: | |
q.put(("down", press)) | |
if __name__ == '__main__': | |
q = Queue() | |
C = Autoscroll(q) | |
C.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment