Пример #1
0
def straight():
    ##    if random.randrange(4) == 2:
    ##        ReleaseKey(W)
    ##    else:
    PressKey(W)
    ReleaseKey(A)
    ReleaseKey(D)
Пример #2
0
def no_keys():

    if random.randrange(0, 3) == 1:
        PressKey(W)
    else:
        ReleaseKey(W)
    ReleaseKey(A)
    ReleaseKey(S)
    ReleaseKey(D)
Пример #3
0
def go_right():
    i = 5
    while (i < 0):
        PressKey(D)
        i = i - 1
    #PressKey(D)
    ReleaseKey(A)
    ReleaseKey(S)
    time.sleep(d_time)
Пример #4
0
def go_left():
    i = 5
    while (i < 0):
        PressKey(A)
        i = i - 1

    ReleaseKey(S)
    ReleaseKey(D)
    time.sleep(d_time)
Пример #5
0
def left():
    # print(straight_frame_diff)
    ReleaseKey(D)
    PressKey(A)
    #ReleaseKey(W)
    if AUTO_STRAIGHT and straight_frame_diff >= 5:
        PressKey(W)
        time.sleep(t_time)
        ReleaseKey(A)
    time.sleep(t_time)
    ReleaseKey(A)
def left():
    global AUTO_STRAIGHT
    # print(straight_frame_diff)
    ReleaseKey(D)
    PressKey(A)
    if AUTO_STRAIGHT:
        PressKey(W)

    time.sleep(t_time)

    ReleaseKey(A)
    ReleaseKey(W)
def right():
    global AUTO_STRAIGHT
    # PressKey(W)
    ReleaseKey(A)
    PressKey(D)
    if AUTO_STRAIGHT:
        PressKey(W)

    time.sleep(t_time)

    ReleaseKey(W)
    ReleaseKey(D)
Пример #8
0
def right(AUTO_STRAIGHT, straight_frame_diff):
    # PressKey(W)
    ReleaseKey(A)
    PressKey(D)
    if AUTO_STRAIGHT and straight_frame_diff >= 5:
        print("going forward")
        PressKey(W)
        time.sleep(t_time)
        ReleaseKey(W)
    #ReleaseKey(W)
    #ReleaseKey(D)
    time.sleep(t_time)
    ReleaseKey(D)
Пример #9
0
def PlayCurveFever(statusRefImg, color):
    # Settings

    colors = {
        'red': np.array((69, 69, 255)),
        'pink': np.array((186, 164, 255)),
        'yellow': np.array((43, 233, 255)),
        'green': np.array((48, 255, 106)),
        'aqua': np.array((192, 209, 2)),
        'blue': np.array((255, 68, 68)),
        'orange': np.array((52, 136, 255))
    }
    full = {"top": 10, "left": 1320, "width": 2535 - 1320, "height": 1023 - 10}
    sct = mss.mss()
    PlayerColor = colors[color]  # red
    colMin = PlayerColor - 20
    colMax = PlayerColor + 20
    states = []
    pyauto.click(x=1900, y=500)
    while 'Play':
        last_time = time.time()
        state1, status = cfb.GrabScreen(statusRefImg, sct, full, colMin,
                                        colMax)

        if status == 'Play':
            states.append(state1)
            if (len(states) == 3):
                p1, p2 = cfb.proccesTwoStates(states[0], states[1], states[2])
                fit, params, dists = cfb.getParameters(p1, p2)
                # imgView = cv2.line(state2,
                #                   (int(p2[0]), int(p2[1])),
                #                   (int(params['collisionPoint'][0]), int(params['collisionPoint'][1])),
                #                   (255, 255, 255),
                #                   2)

                # dodac odelglosc punkt przeciecia dla sladu
                print(cfb.checkPathCollsion(states[2], fit, params, p2))
                if cfb.checkPathCollsion(states[2], fit, params, p2):
                    PressKey(A)
                else:
                    ReleaseKey(A)

                if params['walldist'] > 150:
                    #print("UP   |", "DIST: ", params['walldist'], "ANGLE: ", params['angle']
                    ReleaseKey(A)
                else:
                    # print("DOWN |", "DIST: ", params['walldist'], "ANGLE: ", params['angle'])
                    # press = np.abs(params['angle']) * 1.2 / 180
                    PressKey(A)

                states.pop(0)
Пример #10
0
def restart():
    wait()
    time.sleep(1)
    PressKey(SPACE)
    time.sleep(0.05)
    ReleaseKey(SPACE)
    time.sleep(0.2)
Пример #11
0
def main():
    model = create_model()
    model.load_weights('model_opt.hdf')

    #    weights = model.layers[0].get_weights()[0]
    #    biases = model.layers[0].get_weights()[1]

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

    paused = False
    while (True):

        if not paused:
            screen = grab_screen(region=(0, 64, 640, 480))
            screen = cv2.resize(screen, (160, 120))
            screen = cv2.cvtColor(screen, cv2.COLOR_BGR2RGB)
            screen = np.expand_dims(screen, axis=0)
            prediction = model.predict(screen)[0]
            #            print(prediction)

            maxval = max(prediction)

            if prediction[1] == maxval:
                straight()
                print('straigh', maxval)
            elif prediction[2] == maxval:
                right()
                print('right', maxval)
            elif prediction[0] == maxval:
                left()
                print('left', maxval)

        keys = key_check()

        if 'P' in keys:
            if paused:
                paused = False
                time.sleep(1)
            else:
                paused = True
                ReleaseKey(A)
                ReleaseKey(W)
                ReleaseKey(D)
                time.sleep(1)
Пример #12
0
def realese_key():
    global key_pressed, current_key
    # Se liberan las teclas que hayan sido presionadas, para seguir jugando
    if not key_pressed and current_key != 0:
        for key in current_key:
            ReleaseKey(key)
            current_key = set()
    key_pressed = False
def straight():
    # ReleaseKey(A)
    # ReleaseKey(D)
    PressKey(W)

    time.sleep(t_time_for_fwd)

    ReleaseKey(W)
Пример #14
0
def controller(key):
    if chr(key) == 'A':
        PressKey(A)
        print("A")
        time.sleep(0.10)
        ReleaseKey(A)
    if chr(key) == 'B':
        PressKey(B)
        print("B")
        time.sleep(0.10)
        ReleaseKey(B)
    if chr(key) == 'U':
        PressKey(Z)
        print("U")
        time.sleep(0.10)
        ReleaseKey(Z)
    if chr(key) == 'D':
        PressKey(S)
        print("D")
        time.sleep(0.10)
        ReleaseKey(S)
Пример #15
0
def screen_record(): 
	bulletsFired = 1
	clipSize = 6
	while(True):
		image =  np.array(ImageGrab.grab(bbox=(startx,starty,1200,958)))
		original_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
		cv2.imshow("origi", original_image)
		print("brown ", original_image[761 - starty, 649 - startx])
		if original_image[761 - starty, 649 - startx] > 180 :
			time.sleep(3)
			upgradeGun()
			clipSize+=3
			time.sleep(3)

		for cordsy in range(1,original_image.shape[0], 2):
					for cordsx in range(1,original_image.shape[1], 2):
						if original_image[cordsy][cordsx] < 5:
							max_previous_click_length = 5
							click_bubble_range = 50
							too_close = False
							for pos in previous_clicks:
								if dist(cordsx + startx, cordsy+ starty, pos[0], pos[1]) < click_bubble_range:
									too_close = True
									break
							if too_close:
								continue
							print("Clicked ", cordsx, cordsy)
							pyautogui.click(cordsx + startx + 10, cordsy + starty, 2)
							bulletsFired+=2
							previous_clicks.append([cordsx +startx, cordsy+ starty])
							if len(previous_clicks) > max_previous_click_length:
								del previous_clicks[0]
							if bulletsFired>clipSize:
								PressKey(SPACE)
								time.sleep(0.05)
								bulletsFired = 1
								ReleaseKey(SPACE)
							break

		
		if cv2.waitKey(25) & 0xFF == ord('q'):
			cv2.destroyAllWindows()
			break
Пример #16
0

while True:
    if keyboard.is_pressed('a'):
        while True:
            ammo_screen = np.array(
                ImageGrab.grab(bbox=ammo_coords))  #shape is [y,x]
            ammo_screen = cv2.cvtColor(
                ammo_screen, cv2.COLOR_BGR2GRAY)  # convert to grey image

            #checkscreen()
            #shoot()

            if ammo_screen[5][5] > 200:  #ammo empty
                PressKey(SPACE)
                time.sleep(0.05)
                ReleaseKey(SPACE)
                time.sleep(0.5)

            if ammo_screen[5][5] < 190:  #ammo full
                screen = np.array(
                    ImageGrab.grab(bbox=game_coords))  # shape is [y,x]
                screen = cv2.cvtColor(
                    screen, cv2.COLOR_BGR2GRAY)  # convert to grey image
                shoot()

            if keyboard.is_pressed('q'):
                break

            #time.sleep(0.001)
Пример #17
0
from socket import socket, gethostbyname, AF_INET, SOCK_DGRAM
import sys
from directKeys import PressKey, ReleaseKey, W, A
import time

PORT_NUMBER = 5000
SIZE = 1024

hostName = gethostbyname('192.168.1.125')

mySocket = socket(AF_INET, SOCK_DGRAM)
mySocket.bind((hostName, PORT_NUMBER))

print("Test server listening on port {0}\n".format(PORT_NUMBER))

while True:
    (data, addr) = mySocket.recvfrom(SIZE)
    meme = data.decode('utf-8')
    print(meme)
    if meme == 'On':
        PressKey(W)
        time.sleep(1)
        ReleaseKey(W)
    else:
        ReleaseKey(W)

sys.ext()
Пример #18
0
def release_all():
     ReleaseKey(A)
     ReleaseKey(W)
     ReleaseKey(D)
Пример #19
0
def forward():
     PressKey(W)
     ReleaseKey(A)
     ReleaseKey(D)
Пример #20
0
def left():
     PressKey(W)
     PressKey(A)
     ReleaseKey(D)
     time.sleep(deviationSpeed)
     ReleaseKey(A)
Пример #21
0
def right():
     PressKey(W)
     PressKey(D)
     ReleaseKey(A)
     time.sleep(deviationSpeed)
     ReleaseKey(D)
Пример #22
0
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
                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),
        (width // 2 + windowSize // 2, width // 2 + windowSize // 2),
        (255, 255, 255), 1)
    cv2.imshow("Frame", frame_copy)

    #We need to release the pressed key if none of the key is pressed else the program will keep on sending
    # the presskey command
    if not keyPressed and len(current_key_pressed) != 0:
        for key in current_key_pressed:
            ReleaseKey(key)
        current_key_pressed = set()

    #to release keys for left/right with keys of up/down remain pressed
    if not keyPressed_lr and ((A in current_key_pressed) or
                              (D in current_key_pressed)):
        if A in current_key_pressed:
            ReleaseKey(A)
            current_key_pressed.remove(A)
        elif D in current_key_pressed:
            ReleaseKey(D)
            current_key_pressed.remove(D)

    key = cv2.waitKey(1) & 0xFF

    # if the 'q' key is pressed, stop the loop
Пример #24
0
def go_reverse_right():
    PressKey(S)
    PressKey(D)
    ReleaseKey(W)
    ReleaseKey(A)
def main():
    global AUTO_STRAIGHT
    last_time = time.time()
    for i in list(range(4))[::-1]:
        print(i + 1)
        time.sleep(1)

    paused = False

    frame_number = 0
    while (True):

        frame_number += 1

        if not paused:
            # 800x600 windowed mode
            #screen =  np.array(ImageGrab.grab(bbox=(0,40,800,640)))
            # FOR GTA-SA
            screen = grab_screen(region=(1, 35, 640, 420))
            # print('loop took {} seconds'.format(time.time()-last_time))
            last_time = time.time()
            screen = cv2.cvtColor(screen, cv2.COLOR_BGR2GRAY)
            screen = cv2.resize(screen, (160, 120))

            prediction = model.predict([screen.reshape(160, 120, 1)])[0]
            print(prediction)

            # turn_thresh = .75
            turn_thresh = .65
            fwd_thresh = 0.70

            pred_max = np.argmax(prediction)

            if frame_number % 60 == 0:
                AUTO_STRAIGHT = not AUTO_STRAIGHT

            if pred_max == 0:
                # print(straight_frame_diff)
                left()
                print("a")
            elif pred_max == 1:
                straight()
                print("w")
            else:
                right()
                print("d")

                # print("going forward")
            # if prediction[1] > fwd_thresh:
            #     # straight()
            #     print("w")
            # elif prediction[0] > turn_thresh:
            #     left()
            #     print("a")
            # elif prediction[2] > turn_thresh:
            #     right()
            #     print("d")
            # else:
            #     # straight()
            #     print("i have no idea so w")

        keys = key_check()

        # p pauses game and can get annoying.
        if 'T' in keys:
            if paused:
                paused = False
                time.sleep(1)
            else:
                paused = True
                ReleaseKey(A)
                ReleaseKey(W)
                ReleaseKey(D)
                time.sleep(1)
        if 'E' in keys:
            break
Пример #26
0
def t_key(key_a, key_b, key_c):
    PressKey(key_a)
    ReleaseKey(key_b)
    ReleaseKey(key_c)
    time.sleep(keytime)
Пример #27
0
def slow_ya_roll():
    ReleaseKey(W)
    ReleaseKey(A)
    ReleaseKey(D)
Пример #28
0
def straight():
    PressKey(W)
    ReleaseKey(A)
    ReleaseKey(D)
Пример #29
0
def left():
    PressKey(A)
    # ReleaseKey(W) # this was commented
    ReleaseKey(D)
Пример #30
0
def right():
    PressKey(D)
    ReleaseKey(A)