-
Notifications
You must be signed in to change notification settings - Fork 0
/
trex_getdata.py
executable file
·89 lines (54 loc) · 1.4 KB
/
trex_getdata.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Feb 22 01:38:22 2021
@author: buzun
"""
import keyboard
import uuid
import time
from PIL import Image
from mss import mss
import os
import glob
"""
game address
http://www.trex-game.skipser.com/
"""
# game map
limits = {"top":375, "left": 740, "width":250, "height": 100 }
# mss is cuts region of interest frame
sct = mss()
if os.path.exists("./img"):
files = glob.glob('./img/*')
for f in files:
os.remove(f)
else:
os.makedirs("./img")
i = 0
def recordScreen(recordID, key):
global i
i += 1
print("{}: {}".format(key, i))
img = sct.grab(limits)
im = Image.frombytes("RGB", img.size, img.rgb)
im.save("./img/{}_{}_{}.png".format(key, recordID, i))
isExit = False
def exit():
global isExit
isExit = True
keyboard.add_hotkey("esc", exit)
recordID = uuid.uuid4()
while True:
if isExit: break
try:
if keyboard.is_pressed(keyboard.KEY_UP):
recordScreen(recordID, "up")
time.sleep(0.3)
elif keyboard.is_pressed(keyboard.KEY_DOWN):
recordScreen(recordID, "down")
time.sleep(0.3)
elif keyboard.is_pressed("right"):
recordScreen(recordID, "right")
time.sleep(0.3)
except RuntimeError: continue