Run script from cmd.
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 40 41 42 | # -*- coding: utf-8 -*-
'''
Click counter
Left click: +1
Right click: -1
Middle click: Reset
'''
import pyHook
import pythoncom
print(__doc__)
click = 0
def left_down(event):
global click
click += 1
print(click)
return True
def right_down(event):
global click
click -= 1
print(click)
return True
def middle_down(event):
global click
click = 0
print(click)
return True
hm = pyHook.HookManager()
hm.SubscribeMouseLeftDown(left_down)
hm.SubscribeMouseRightDown(right_down)
hm.SubscribeMouseMiddleDown(middle_down)
hm.HookMouse()
pythoncom.PumpMessages()
hm.UnhookMouse()
|
Here is my version of the Click Counter, using only Tkinter which is a default module, unlike pyHook and pythoncom are.
Thanks! The difference is that you're counting clicks only within a Tkinter window. I use my script for counting objects in complex CAD drawings, PDF files, etc. -- just clicking.