This repository was archived by the owner on Feb 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClickFix.py
More file actions
95 lines (72 loc) · 2.03 KB
/
ClickFix.py
File metadata and controls
95 lines (72 loc) · 2.03 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
from typing import Tuple
import psutil
import os
import math
import pythoncom
import pyWinhook as pyHook
import ctypes
MOVING: int = 512
DOWN: int = 513
UP: int = 514
MIN_DELAY: int = 130 # ms
MIN_DISTANCE: int = 10 # px
SELECTION_RATE: float = 2
mouseLock: bool = False
mouseIsUp: bool = True
lastClickUpTime: int = 0
lastClickUpPos: Tuple[int, int] = (-1, -1)
lastClickRealDownPos: Tuple[int, int] = (-1, -1)
def set_high_priority():
p = psutil.Process(os.getpid())
p.nice(psutil.HIGH_PRIORITY_CLASS)
def get_distance(pos_1, pos_2):
return math.sqrt((pos_2[0] - pos_1[0])**2 + (pos_2[1] - pos_1[1])**2)
def mouse_up(hndl, pos):
hndl.UnhookMouse()
import win32con
ctypes.windll.user32.mouse_event(win32con.MOUSEEVENTF_ABSOLUTE | win32con.MOUSEEVENTF_LEFTUP, pos[0], pos[1], 0, 0)
hndl.HookMouse()
def on_mouse_event(event):
global hm
global MOVING
global DOWN
global UP
global MIN_DELAY
global mouseLock
global mouseIsUp
global lastClickUpTime
global lastClickUpPos
global lastClickRealDownPos
if mouseLock and mouseIsUp and (
(event.Time - lastClickUpTime > MIN_DELAY * SELECTION_RATE) or
(event.Time - lastClickUpTime > MIN_DELAY and get_distance(
event.Position, lastClickRealDownPos) <= MIN_DISTANCE)
):
mouse_up(hm, lastClickUpPos)
mouseLock = False
if event.Message == UP:
mouseIsUp = True
mouseLock = True
lastClickUpTime = event.Time
lastClickUpPos = event.Position
return False
if event.Message == DOWN:
set_high_priority()
mouseIsUp = False
if not mouseLock:
mouseLock = True
lastClickRealDownPos = event.Position
return True
else:
return False
return True
# set high priority
set_high_priority()
# create a hook manager
hm = pyHook.HookManager()
# watch for all mouse events
hm.MouseAll = on_mouse_event
# set the hook
hm.HookMouse()
# wait forever
pythoncom.PumpMessages()