-
Notifications
You must be signed in to change notification settings - Fork 0
/
events.py
63 lines (46 loc) · 1.61 KB
/
events.py
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
import datetime
import pyautogui
from timer import Timer
pyautogui.PAUSE = 0
class Event:
def __init__(self):
pass
def process(self):
pass
@classmethod
def createEvent(cls, event_type, *args):
if issubclass(event_type, Event):
return event_type(*args)
return None
class MouseEvent(Event):
def __init__(self, x: int, y: int):
super().__init__()
self._x = x
self._y = y
def process(self):
now = datetime.datetime.now().time()
print(f'[{now}] Mouse clicked at x={self._x} y={self._y}')
pyautogui.click(self._x, self._y)
def __str__(self):
return f'mouse;x={self._x};y={self._y}'
class TimeEvent(Event):
def __init__(self, timer_type, hour, minute, second, microsecond):
super().__init__()
self._type = timer_type
self._h = hour
self._m = minute
self._s = second
self._us = microsecond
if timer_type == 'clock':
self._timer = Timer.fromClock(hour, minute, second, microsecond)
elif timer_type == 'duration':
self._timer = Timer.fromDuration(hour, minute, second, microsecond)
else:
raise ValueError("Invalid timer type.")
def process(self):
t = 'until systime' if self._type == 'clock' else 'for'
now = datetime.datetime.now().time()
print(f'[{now}] Timer waits {t} {self._h:02d}:{self._m:02d}:{self._s:02d}.{self._us:06d}')
self._timer.waitForTimeout()
def __str__(self):
return f'time;t={self._type};h={self._h};m={self._m};s={self._s};u={self._us}'