-
Notifications
You must be signed in to change notification settings - Fork 0
/
logic.py
31 lines (24 loc) · 1.04 KB
/
logic.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
"""Модуль представляет из себя описание логики записи последовательности кликов мышки и ее остановки по нажатию нужного символа с клавиатуры"""
from pynput import mouse, keyboard
from datetime import datetime
import json
sequence = {}
new_file = open(f'{datetime.now().strftime("%m-%d-%Y, %H:%M:%S")}.txt', "w")
with open('stop_button.txt') as g:
stop_button = g.read()
def on_release(key):
if key.char == stop_button.lower():
json.dump(sequence, new_file)
new_file.close()
m_listener.stop()
return False
def on_click(x, y, button, pressed):
print('{0} at {1}'.format(
'Pressed' if pressed else 'Released',
(x, y)))
print(datetime.now())
sequence[datetime.now().strftime("%m/%d/%Y, %H:%M:%S.%f")[:-3]] = (x, y)
with mouse.Listener(on_click=on_click) as m_listener, \
keyboard.Listener(on_release=on_release) as k_listener:
m_listener.join()
k_listener.join()