i am using PyMouse(Event) for detecting if mouse button is pressed:
from pymouse import PyMouseEvent
class DetectMouseClick(PyMouseEvent):
def __init__(
I think as Oli points out in his comment there isn't a constant stream of clicks when the mouse button is held down so you'll have to have the print
in a loop. Having the while
loop running on the same thread prevents the click event firing when the mouse is released so the only way I can think of to achieve what you are after is to print("click")
from a separate thread.
I'm not a Python programmer but I've had a stab which works on my machine (Python 2.7 on Windows 8.1):
from pymouse import PyMouseEvent
from threading import Thread
class DetectMouseClick(PyMouseEvent):
def __init__(self):
PyMouseEvent.__init__(self)
def print_message(self):
while self.do == 1:
print("click")
def click(self, x, y, button, press):
if button == 1:
if press:
print("click")
self.do = 1
self.thread = Thread(target = self.print_message)
self.thread.start()
else:
self.do = 0
print("end")
else:
self.do = 0
self.stop()
O = DetectMouseClick()
O.run()