-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecord.py
70 lines (56 loc) · 1.77 KB
/
record.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
64
65
66
67
68
69
import os
import pyautogui
import keyboard
import json
from pynput import mouse
import generate_code
interactions = []
isTerminate = False
file_name = 'interactions.json'
running = True
#file
def save_file():
global interactions
with open(os.path.join('.','interactions',file_name), 'w') as json_file:
json.dump(interactions, json_file)
#interactions
def save_mouse_interaction(mouse_pos, mouse_clic):
interactions.append((mouse_pos.x, mouse_pos.y))
interactions.append((mouse_clic))
def save_key_intaraction(key_code):
interactions.append(key_code)
#events
def on_key_press(event):
global isTerminate
global running
if event.name == "esc" and not isTerminate:
isTerminate = True
return
elif event.name == "esc" and isTerminate:
save_file()
running = False
return
save_key_intaraction(event.name)
isTerminate = False
def capture_input():
keyboard.on_press(on_key_press)
global running
while running:
with mouse.Events() as events:
for event in events:
if isinstance(event, mouse.Events.Click):
if event.button == mouse.Button.left and event.pressed:
save_mouse_interaction(pyautogui.position(), 'LC')
if event.button == mouse.Button.right and event.pressed:
save_mouse_interaction(pyautogui.position(), 'RC')
if not running:
break
def record():
print("Leyendo teclado...")
capture_input()
print("Archivo 'interactions.json' generado.")
if __name__ == '__main__':
interactions = []
code_name = input('Enter file name to code: ')
record()
generate_code.create_file(code_name)