def right():
    if random.randrange(0, 3) == 1:
        PressKey(W)
    else:
        ReleaseKey(W)
    PressKey(D)
    ReleaseKey(A)
    ReleaseKey(S)
Exemple #2
0
def right():
    PressKey(D)
    time.sleep(0.175)
    PressKey(W)
    time.sleep(0.025)
    ReleaseKey(D)
    ReleaseKey(W)
    ReleaseKey(A)
    ReleaseKey(S)
Exemple #3
0
def do_action(key):
    if key == 0:
        pass  # Nothing
    elif key == 1:
        PressKey(game_keys[0])  # Left
    elif key == 2:
        PressKey(game_keys[1])  # Right
    elif key == 3:
        PressKey(game_keys[1])  # Right + Jump
        PressKey(game_keys[3])
    elif key == 4:
        PressKey(game_keys[3])  # Jump
Exemple #4
0
def brake():
    PressKey(S)
    time.sleep(0.2)
    ReleaseKey(W)
    ReleaseKey(A)
    ReleaseKey(D)
    ReleaseKey(S)
Exemple #5
0
def accelerate():
    PressKey(W)
    time.sleep(0.2)
    ReleaseKey(A)
    ReleaseKey(D)
    ReleaseKey(S)
    ReleaseKey(W)
Exemple #6
0
 def turn(self, action):
     if self.mouse_up and action >= 0.5:
         PressKey(W)
         self.mouse_up = False
         self.have_turned = True
     if not self.mouse_up and action < 0.5:
         ReleaseKey(W)
         self.mouse_up = True
def no_keys():

    if random.randrange(0, 3) == 1:
        PressKey(W)
    else:
        ReleaseKey(W)
    ReleaseKey(A)
    ReleaseKey(S)
    ReleaseKey(D)
Exemple #8
0
 def reset(self):
     print('reset')
     self.turn(-1)
     time.sleep(1.3)
     PressKey(Q)
     screen = self.get_screen()
     time.sleep(0.05)
     row, col, is_nan = self.process_img(screen)
     state = [row, col, 0, int(self.mouse_up)]
     self.ep_start = time.time()
     self.time_checked = self.ep_start
     self.have_turned = False
     self.prev_state = [row, col]
     ReleaseKey(Q)
     print('exit_reset')
     return state
Exemple #9
0
def straight():
    PressKey(W)
    ReleaseKey(A)
    ReleaseKey(D)
def reverse_right():
    PressKey(S)
    PressKey(D)
    ReleaseKey(W)
    ReleaseKey(A)
def reverse_left():
    PressKey(S)
    PressKey(A)
    ReleaseKey(W)
    ReleaseKey(D)
def forward_right():
    PressKey(W)
    PressKey(D)
    ReleaseKey(A)
    ReleaseKey(S)
Exemple #13
0
def pause_button():
    PressKey(ESC)
    ReleaseKey(ESC)
Exemple #14
0
import numpy as np
import cv2
import os
import glob
import time
from PIL import ImageGrab, Image
from direct_keys import PressKey, ReleaseKey, W, A, S, D
# Preallocating screengrab array
screengrab = np.zeros((480, 640, 3))

for i in list(range(4))[::-1]:
    print(i + 1)
    time.sleep(1)

print('down')
PressKey(W)
time.sleep(5)
ReleaseKey(A)
print('up')
PressKey(S)
time.sleep(3)


def process_screengrab(orig_image):
    # colored image = [[0-255],[0-255],[0-255]] GRAY = [0-255]
    processed_image = cv2.cvtColor(orig_image, cv2.COLOR_BGR2GRAY)
    processed_image = cv2.adaptiveThreshold(processed_image,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,\
            cv2.THRESH_BINARY,15,5)
    # processed_image = cv2.Canny(processed_image,threshold1=100,threshold2=300)
    return processed_image
Exemple #15
0
import numpy as np
import os
import sys
import tensorflow as tf

import cv2
import time

from direct_keys import PressKey, Z
from grabscreen import grab_screen, process_img

START_TIMEOUT = 5

if __name__ == "__main__":
    # last_time = time.time()
    print("starting in {}s ...".format(START_TIMEOUT))
    time.sleep(START_TIMEOUT)
    while True:
        PressKey(Z)
        screen = grab_screen()
        # print('Frame took {} seconds'.format(time.time() - last_time))
        # last_time = time.time()
        processed_img = process_img(screen)
        cv2.imshow(
            "object detection",
            cv2.resize(processed_img, (480, 372),
                       interpolation=cv2.INTER_NEAREST))
        k = cv2.waitKey(30) & 0xff
        if k == 27:
            break
def right():
    PressKey(Z)
    PressKey(L)
    ReleaseKey(J)
def left():
    PressKey(Z)
    PressKey(J)
    ReleaseKey(L)
def straight():
    PressKey(Z)
    ReleaseKey(J)
    ReleaseKey(L)
Exemple #19
0
def press_label(label):
    global last_print_time
    if time.time() - last_print_time > 1:
        last_print_time = time.time()
        print(label)
    if simulate:
        return
    if label == "NO":
        release_all()
        pass
    # release_all()
    elif label == "WA":
        PressKey(W)
        PressKey(A)
        ReleaseKey(S)
        ReleaseKey(D)
    elif label == "WD":
        PressKey(W)
        PressKey(D)
        ReleaseKey(A)
        ReleaseKey(S)
    elif label == "AS":
        PressKey(A)
        PressKey(S)
        ReleaseKey(W)
        ReleaseKey(D)
    elif label == "SD":
        PressKey(S)
        PressKey(D)
        ReleaseKey(W)
        ReleaseKey(A)
    elif label == "A":
        PressKey(A)
        ReleaseKey(W)
        ReleaseKey(S)
        ReleaseKey(D)
    elif label == "D":
        PressKey(D)
        ReleaseKey(W)
        ReleaseKey(A)
        ReleaseKey(S)
    elif label == "S":
        PressKey(S)
        ReleaseKey(W)
        ReleaseKey(A)
        ReleaseKey(D)
    elif label == "W":
        PressKey(W)
        ReleaseKey(A)
        ReleaseKey(S)
        ReleaseKey(D)
Exemple #20
0
def left():
    PressKey(A)
    PressKey(W)
    ReleaseKey(D)
Exemple #21
0
def right():
    PressKey(D)
    PressKey(W)
    ReleaseKey(A)
def reverse():
    PressKey(S)
    ReleaseKey(A)
    ReleaseKey(W)
    ReleaseKey(D)
def movimiento():
    PressKey(W)
    print('key pressed')
    #time.sleep(5)
    ReleaseKey(W)
def forward_left():
    PressKey(W)
    PressKey(A)
    ReleaseKey(D)
    ReleaseKey(S)