예제 #1
0
def workout():
    directkeys.PressKey(target)
    time.sleep(.05)
    directkeys.ReleaseKey(target)
    directkeys.PressKey(auto_operate)
    time.sleep(.05)
    directkeys.ReleaseKey(auto_operate)
예제 #2
0
def make_something(word_command):
    # обращение к боту
    for i in range(len(patternCommand.bot)):
        if word_command.find(patternCommand.bot[i]) > -1:
            print("Шо надо\n-=-=-=-=-=-=-=-=-=-")
            playsound("voice/sho.mp3")
            word_command = command(True)

            # активация варп-двигателя
            for counter in range(len(patternCommand.warp_drive)):
                if word_command.find(patternCommand.warp_drive[counter]) > -1:
                    print(patternCommand.warp_drive[counter])
                    print('Готово\n-=-=-=-=-=-=-=-=-=-')
                    directkeys.PressKey(hexDirKey.C)
                    directkeys.ReleaseKey(hexDirKey.C)
                    playsound("voice/varp_aktivirovan.mp3")
                    return

            # убрать/выпустить шасси
            for counter in range(len(patternCommand.landing_gear)):
                if word_command.find(
                        patternCommand.landing_gear[counter]) > -1:
                    print(patternCommand.landing_gear[counter])
                    print("шасси активированы\n-=-=-=-=-=-=-=-=-=-")
                    directkeys.PressKey(hexDirKey.G)
                    directkeys.ReleaseKey(hexDirKey.G)
                    playsound("voice/shassi.mp3")
                    return

            # запросить стыковку
            for counter in range(len(patternCommand.docking)):
                if word_command.find(patternCommand.docking[counter]) > -1:
                    return

            # ночное зрение
            for counter in range(len(patternCommand.night_vision)):
                if word_command.find(
                        patternCommand.night_vision[counter]) > -1:
                    directkeys.PressKey(hexDirKey.I)
                    directkeys.ReleaseKey(hexDirKey.I)
                    playsound("voice/nochnoe.mp3")
                    return

            # рассказать сказку
            for counter in range(len(patternCommand.story)):
                if word_command.find(patternCommand.story[counter]) > -1:
                    print(patternCommand.story[counter])
                    print("Как дед насрал в каляску\n-=-=-=-=-=-=-=-=-=-")
                    playsound("voice/skazka.mp3")
                    return
예제 #3
0
    def play(self):

        sleep(1)
        print("Playing. Press 1 to stop.")
        while not keyboard.is_pressed('1'):
            movement = AI.query()
            for i, key in enumerate(KEY_LIST):
                if movement[i] > self.KEYPRESS_THRESHOLD:
                    directkeys.PressKey(key)
                else:
                    directkeys.ReleaseKey(key)
        print("Done playing.")
        for key in KEY_LIST:
            directkeys.ReleaseKey(key)
예제 #4
0
def release(key):
    """Releases the given key"""
    if DEBUG and DEBUG_CONTROL:
        print("release", key)
    global action_stack
    if key in action_stack:
        del action_stack[action_stack.index(key)]
    dk.ReleaseKey(key)
예제 #5
0
def track(distance_threshold, degree_threshold):
    key = None

    screen = pyautogui.screenshot(region=(0, 80, 1024, 716))
    radar = screen.crop((876, 537, 1023, 684))
    mobs = find_mob(radar)
    if closest_mob(mobs) == None:
        return False
    deg, distance = mob_to_parallel(closest_mob(mobs))
    #print(deg, distance)

    while distance > distance_threshold or abs(deg) > degree_threshold:
        print("searching")
        screen = pyautogui.screenshot(region=(0, 80, 1024, 716))
        radar = screen.crop((876, 537, 1023, 684))

        mobs = find_mob(radar)
        deg, distance = mob_to_parallel(closest_mob(mobs))

        #print(deg, distance)

        if deg > degree_threshold:
            if key != None:
                directkeys.ReleaseKey(key)
            key = c
            directkeys.PressKey(c)
        elif deg < -degree_threshold:
            if key != None:
                directkeys.ReleaseKey(key)
            key = z
            directkeys.PressKey(z)
        else:
            if key == None:
                pass

            else:
                directkeys.ReleaseKey(key)

        directkeys.PressKey(w)
        #time.sleep(.05)

    if key != None: directkeys.ReleaseKey(key)
    directkeys.ReleaseKey(w)

    return distance < distance_threshold and abs(deg) < degree_threshold
예제 #6
0
    def test_movement(self):

        print("Testing movement now.")

        directkeys.PressKey('up')
        sleep(5)
        directkeys.ReleaseKey('up')

        print("Done testing movement.")
예제 #7
0
def pause_game():
    global game_paused
    if game_paused:
        # Resume actions
        dk.PressKey(dk.SCANCODES["ESC"])
        time.sleep(0.2)
        dk.ReleaseKey(dk.SCANCODES["ESC"])
        for key in action_stack:
            dk.PressKey(key)
        print("Resuming Game.")
    else:
        # Release keys while paused
        for key in action_stack:
            dk.ReleaseKey(key)
        dk.PressKey(dk.SCANCODES["ESC"])
        time.sleep(0.2)
        dk.ReleaseKey(dk.SCANCODES["ESC"])
        print("Pausing Game.")
    game_paused = not game_paused
예제 #8
0
def pause(*param):
    global active
    if not active:
        # Resume actions
        for key in action_stack:
            dk.PressKey(key)
        print("Resuming.")
    else:
        # Release keys while paused
        for key in action_stack:
            dk.ReleaseKey(key)
        print("Pausing.")
    active = not active
예제 #9
0
def main():

    # So it does arrow keys, not numbers
    directkeys.PressKey(SHIFT)

    while True:

        # set up the game
        setup()

        # a var so we know how long we've held the up key
        prevJumpTime = 0

        # declare globality of variables
        global lost
        global sensor

        # repeat as long as the game is not yet lost
        while True:

            # update the sensor
            sensor.update()

            # iterate through each frame of a certain area
            for i in range(sensor.rangeOfSensor):

                #    lower sensor                      higher sensor
                if sensor.currentLowPixel(i) != sensor.lowBackground(
                ) or sensor.currentHighPixel(i) != sensor.highBackground():
                    prevJumpTime = millis()
                    directkeys.PressKey(UP)
                else:
                    curTime = millis()
                    if curTime - prevJumpTime >= 100:
                        directkeys.ReleaseKey(UP)

        # Restart after losing
        directkeys.PressKey(UP)
        directkeys.ReleaseKey(UP)
import socket
import directkeys

ip = "192.168.11.128"
port = 6969

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind((ip, port))

keys = [
    directkeys.D, directkeys.S, directkeys.W, directkeys.A, directkeys.SPACE,
    directkeys.ESC
]

while True:
    data, addr = s.recvfrom(1024)
    x = data.decode()
    for i in range(len(x)):
        if (x[i] == "1"):
            directkeys.PressKey(keys[i])
        else:
            directkeys.ReleaseKey(keys[i])
    #print(x)
예제 #11
0
 def tap(self, key):
     dx_scan_code = self.key_options[key.lower()]
     directkeys.PressKey(dx_scan_code)
     time.sleep(self.time)
     directkeys.ReleaseKey(dx_scan_code)
예제 #12
0
 def select_search_bar():
     dk.MaintainKey('ctrl')
     dk.PressKey('l')
     dk.ReleaseKey('ctrl')
예제 #13
0
    if write_out:
        cv2.imwrite('res.png', img_rgb)

    return matched


def workout():
    directkeys.PressKey(target)
    time.sleep(.05)
    directkeys.ReleaseKey(target)
    directkeys.PressKey(auto_operate)
    time.sleep(.05)
    directkeys.ReleaseKey(auto_operate)


if __name__ == '__main__':
    working = False
    while True:
        #screenshot = pyautogui.screenshot('game.png', region=(0, 80, 1024, 716))
        while template_match('dead.jpg'):
            working = False
            directkeys.PressKey(loot)
            time.sleep(.05)
            directkeys.ReleaseKey(loot)
        if not in_range(8):
            track(6, 10)
        elif not working:
            workout()
            working = True
예제 #14
0
파일: auto.py 프로젝트: covopd/automation
def autoFishing():

    window = gw.getWindowsWithTitle('BlueStacks')[0]
    window.resizeTo(600, 400)
    window.moveTo(0, 0)  # move window to 10, 10

    print('Start Capture')

    #window.focus() does not work
    mc.click(600, 400)

    # 500loops = 1fish
    for i in range(500 * 5000):

        screen = grapscreen.grab_screen(region=(0, 0, 800, 500))

        ######################################################################
        # 1. Ad
        m = np.mean(screen[80:120, 50:750])
        cv2.rectangle(screen, (50, 80), (750, 120), 255, 2)
        print('Ad: {:.1f}'.format(m))
        # 106.7
        if m > 104 and m < 107:
            print('Skip Ad')
            mc.click(scale(740), scale(100))

        ######################################################################
        # 2. Cast button (168.0)
        m = np.mean(screen[450:480, 700:750])
        cv2.rectangle(screen, (700, 450), (750, 480), 255, 2)
        #print('Cast: {:.1f}'.format(m))
        if m > 160 and m < 171:
            print('Cast')
            #mc.click(scale(725),scale(465))
            kb.TypeKey(kb.SPACE)

        ######################################################################
        # 3. Line broken (52.6)
        m = np.mean(screen[100:130, 500:630])
        cv2.rectangle(screen, (500, 100), (630, 130), 255, 2)
        #print('Broken: {:.1f}'.format(m))
        if m > 51 and m < 54:
            print('Broken')
            mc.click(scale(615), scale(115))

        ######################################################################
        # 4. Strike (148.8-149)
        m = np.mean(screen[430:450, 670:720])
        cv2.rectangle(screen, (670, 430), (720, 450), 255, 2)  # strike button
        #print('Strike: {:.1f}'.format(m))
        if m > 146 and m < 152:
            kb.TypeKey(kb.SPACE)  # Strike

            ##################################################################
            # 5.1 gauge
            m = np.mean(screen[90:110, 380:440])
            cv2.rectangle(screen, (380, 90), (440, 110), 255, 2)  # gauge bar
            print('Gauge: {:.1f}'.format(m))
            if m > 104 and m < 114:
                # Press Short (111~113)
                print('Press Short')
                kb.PressKey(kb.SPACE)
                time.sleep(0.2)
                kb.ReleaseKey(kb.SPACE)
            elif m > 61 and m < 64:
                # Press Harder (62~63)
                print('Press Long')
                kb.PressKey(kb.SPACE)
                time.sleep(1.0)
                kb.ReleaseKey(kb.SPACE)

        else:
            ##################################################################
            # Claim appears only when no strike button
            # 5.2 Claim button (174.9)
            m = np.mean(screen[425:460, 120:230])
            cv2.rectangle(screen, (120, 425), (230, 460), 255, 2)
            #print('Claim: {:.1f}'.format(m))
            if m > 174 and m < 176:
                print('Claim')
                # Use mouse to slow down
                #mc.click(scale(140), scale(440))
                kb.TypeKey(kb.SPACE)

        ######################################################################
        # 6. Boss Defeated (166.5)
        bossEnabled = False
        m = np.mean(screen[400:440, 350:450])
        cv2.rectangle(screen, (350, 400), (450, 440), 255, 2)
        #print('Boss: {:.1f}'.format(m))
        if m > 164 and m < 169 and bossEnabled:
            print('Boss Defeated')
            mc.click(scale(400), scale(400))

        ######################################################################
        # 7. Threshold Achieved (32.6, 34.9)
        m = np.mean(screen[60:470, 20:200])
        if m > 30 and m < 37:
            cv2.rectangle(screen, (20, 60), (200, 470), 255, cv2.FILLED)

            # 8. Threshold Achieved Exit (51.9)
            m = np.mean(screen[60:100, 740:790])
            cv2.rectangle(screen, (740, 60), (790, 100), 255, cv2.FILLED)

            if m > 50 and m < 54:
                print('Achievement Exit: {:.1f}'.format(m))
                mc.click(scale(770), scale(77))
            else:
                print('Threshold Acheived: {:.1f}'.format(m))
                mc.click(scale(400), scale(400))

            time.sleep(0.5)

        ######################################################################
        ######################################################################
        cv2.imshow('test window', screen)
        if cv2.waitKey(25) & 0xFF == ord('q'):
            cv2.destroyAllWindows()
            print('Stop Capture')
            break
예제 #15
0
def main():
    for i in list(range(3))[::-1]:
        print(i + 1)
        time.sleep(1)

    window_name = r'MapleStory2 - A New Beginning'

    hwnd = win32gui.FindWindow(None, window_name)

    last_time = time.time()
    paused = False
    print('STARTING!!!')
    while (True):
        if not paused:

            #grabbed_image = cv2.resize(grabbed_image, (640, 360))
            #cv2.imwrite('image.png',grabbed_image)
            #cv2.imshow('window', grabbed_image)
            # resize to something a bit more acceptable for a CNN
            #cv2_image = np.array(grabbed_image.convert('RGB'))

            #grabbed_image.show()
            # screen = grab_screen(window_dimensions)
            # cv2.imshow('MS2', image)
            last_time = time.time()

            #   if active window is our application...
            if win32gui.GetWindowText(
                    win32gui.GetForegroundWindow()) == window_name:
                RGB_image = _get_window_image(hwnd)
                img_HP_bar = _get_HP_bar_image_from_image(RGB_image)
                cv2.imshow("HP Bar", img_HP_bar)
                hp = _get_HP_from_image(img_HP_bar)

                if hp != None:
                    if hp <= 1200:
                        directkeys.PressKey(0x02)
                        time.sleep(.5)
                        directkeys.ReleaseKey(0x02)
                        print("Used potion!")

                # print(hp)
            else:
                print("MS2 is not active window. Doing nothing.")

        #   Press 'T' to pause
        keys = key_check()
        if 'T' in keys:
            if paused:
                paused = False
                print('unpaused!')
                time.sleep(1)
            else:
                print('Pausing!')
                paused = True
                time.sleep(1)

        #   buffer to avoid crashing
        cv2.waitKey(1)

    cv2.destroyAllWindows()
    print("Ended")
예제 #16
0
	def win_release(self, x):
		directkeys.ReleaseKey(x)