-
Notifications
You must be signed in to change notification settings - Fork 2
/
get_data.py
46 lines (35 loc) · 911 Bytes
/
get_data.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
import keyboard
import uuid
import time
from PIL import Image
from mss import mss
# game link: http://www.trex-game.skipser.com/
mon = { "top": 310, "left": 760, "width": 250, "height": 80}
sct = mss()
i = 0
def record_screen(record_id, key):
global i
i += 1
print("{}: {}".format(key,i))
img = sct.grab(mon)
im = Image.frombytes("RGB", img.size, img.rgb)
im.save("./images/{}_{}_{}.png".format(key, record_id, i))
is_exit = False
def exit():
global is_exit
is_exit = True
keyboard.add_hotkey("esc", exit)
record_id = uuid.uuid4()
while True:
if is_exit: break
try:
if keyboard.is_pressed(keyboard.KEY_UP):
record_screen(record_id, "up")
time.sleep(0.1)
elif keyboard.is_pressed(keyboard.KEY_DOWN):
record_screen(record_id, "down")
time.sleep(0.1)
elif keyboard.is_pressed("right"):
record_screen(record_id, "right")
time.sleep(0.1)
except RuntimeError: continue