Created
October 7, 2016 17:39
-
-
Save pykong/8a0a0b5e4c09a603ef46820aa62a4ee4 to your computer and use it in GitHub Desktop.
Gets mouse delta as (x, y) tuple of coordinates.
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
from pymouse import PyMouse, PyMouseEvent | |
from threading import Thread | |
import numpy | |
class DetectMouseClick(PyMouseEvent): | |
def __init__(self): | |
PyMouseEvent.__init__(self) | |
self.mouse = PyMouse() | |
self.start_xy = (0, 0) | |
def print_message(self): | |
while self.do == 1: | |
pass | |
def click(self, x, y, button, press): | |
if button == 1: # left button, customize if required | |
if press: | |
self.do = 1 | |
self.start_xy = self.mouse.position() | |
self.thread = Thread(target=self.print_message) | |
self.thread.start() | |
else: | |
self.do = 0 | |
stop_xy = self.mouse.position() | |
delta_xy = tuple(numpy.subtract(stop_xy, self.start_xy)) # delta_xy | |
print("Delta X, Y: {}".format(delta_xy)) | |
else: | |
self.do = 0 | |
# run mouse event listener with: | |
O = DetectMouseClick() | |
O.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment