def go_forward_right(): PressKey(W) PressKey(D) ReleaseKey(A) ReleaseKey(S)
def right(): ReleaseKey(A) PressKey(W) PressKey(D)
def go_forward_left(): PressKey(W) PressKey(A) ReleaseKey(D) ReleaseKey(S)
def right(): PressKey(D) ReleaseKey(A)
vid = cv2.VideoCapture(0) SpaceBar = 0x20 previous_key = 0 while True: _, frame = vid.read() frame = cv2.resize(frame, (600, 600)) # frame = [600,600, 3] crop = frame[50:400, 200:500] crop = cv2.resize(crop, (100, 100)) crop_dim = tf.expand_dims(crop, 0) prediction = model.predict(crop_dim) print(prediction[0][0]) if int(np.around(prediction[0][0])) == 1: previous_key = 1 PressKey(SpaceBar) ReleaseKey(SpaceBar) time.sleep(0.005) print('pressed') cv2.rectangle(frame, (200, 50), (500, 400), (255, 0, 0), 2) cv2.imshow('frame', frame) if cv2.waitKey(1) == ord('q'): cv2.destroyAllWindows() break
import time from directKeys import PressKey, ReleaseKey, W, A, S, D, f2 for i in list(range(4))[::-1]: print(i + 1) time.sleep(1) PressKey(W) time.sleep(2) ReleaseKey(W)
def straight(): PressKey(W) ReleaseKey(A) ReleaseKey(D)
def forward_left(): print("FORWARD_LEFT") PressKey(W) PressKey(A) ReleaseKey(D)
def forward_right(): print("FORWARD_RIGHT") PressKey(W) PressKey(D) ReleaseKey(A)
def right(): print("RIGHT") ReleaseKey(W) PressKey(D) ReleaseKey(A)
def left(): print("LEFT") ReleaseKey(W) ReleaseKey(D) PressKey(A)
def straight(): print("STRAIGHT") PressKey(W) ReleaseKey(A) ReleaseKey(D)
def left(): PressKey(LEFT) ReleaseKey(RIGHT)
def right(): PressKey(RIGHT) ReleaseKey(LEFT)
def go_reverse_left(): PressKey(S) PressKey(A) ReleaseKey(W) ReleaseKey(D)
import numpy as np from PIL import ImageGrab import cv2 import time import pyautogui from directKeys import PressKey,W,A,S,D import os for i in list(range(4))[::-1]: print(i+1) time.Sleep(1) print('down') PressKey('w') time.Sleep(3) print('up') PressKey('w') def keys_to_output(keys): output = [0,0,0] if 'A' in keys: output[0] =1 elif 'D' in keys: output[2] =1 else: output[1] = 1 return output
def go_reverse_right(): PressKey(S) PressKey(D) ReleaseKey(W) ReleaseKey(A)
def left(): PressKey(A) ReleaseKey(W) ReleaseKey(D) ReleaseKey(A)
def t_key(key_a, key_b, key_c): PressKey(key_a) ReleaseKey(key_b) ReleaseKey(key_c) time.sleep(keytime)
def slow_ya_roll(): PressKey(S) ReleaseKey(W) ReleaseKey(A) ReleaseKey(D)
def left(): PressKey(A) # ReleaseKey(W) # this was commented ReleaseKey(D)
def go_straight(): PressKey(W) ReleaseKey(A) ReleaseKey(D) ReleaseKey(S)
mouse_pos = queryMousePosition() if mouse_pos.x <= 0: break print("alright we good to go") while True: mouse_pos = queryMousePosition() if game_coords[0] < mouse_pos.x < game_coords[2] and game_coords[ 1] < mouse_pos.y < game_coords[3]: start_time = time.time() screen = np.array(ImageGrab.grab(bbox=game_coords)) screen = cv2.cvtColor(screen, cv2.COLOR_BGR2GRAY) if screen[347 - game_coords[1], 684 - game_coords[0]] > 180: PressKey(SPACE) time.sleep(0.05) ReleaseKey(SPACE) if screen[732 - game_coords[1], 872 - game_coords[0]] < 150: shoot_some_fuckers(screen) clicks_per_second = no_of_clicks_this_level / (time.time() - start_time_of_level) print("Clicks per second {}".format(clicks_per_second)) elif screen[732 - game_coords[1], 872 - game_coords[0]] > 250: time.sleep(3) upgrade_gun() time.sleep(3) start_time_of_level = time.time() no_of_clicks_this_level = 0
def go_reverse(): PressKey(S) ReleaseKey(A) ReleaseKey(W) ReleaseKey(D)
# find the center from the moments 0.000001 is added to the denominator so that divide by # zero exception doesn't occur center_left = (int(M["m10"] / (M["m00"] + 0.000001)), int(M["m01"] / (M["m00"] + 0.000001))) # only proceed if the radius meets a minimum size if radius > circle_radius: # draw the circle and centroid on the frame, cv2.circle(frame, (int(x), int(y)), int(radius), (0, 255, 255), 2) cv2.circle(frame, center_left, 5, (0, 0, 255), -1) #the window size is kept 160 pixels in the center of the frame(80 pixels above the center and 80 below) if center_left[0] < (width // 2 - windowSize // 2): cv2.putText(frame, 'LEFT', (20, 50), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255)) PressKey(A) current_key_pressed.add(A) keyPressed = True keyPressed_lr = True elif center_left[0] > (width // 2 + windowSize // 2): cv2.putText(frame, 'RIGHT', (20, 50), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255)) PressKey(D) current_key_pressed.add(D) keyPressed = True keyPressed_lr = True # show the frame to our screen frame_copy = frame.copy() frame_copy = cv2.rectangle( frame_copy, (width // 2 - windowSize // 2, 0),
def left(): ReleaseKey(D) PressKey(W) PressKey(A)