コード例 #1
0
def on_release(key):
    global currentStageName
    global currentStep
    global stepList
    global stage
    global clickImage
    global delay
    global newStepList
    global startTime
    if hasattr(key, "char"):
        if key.char == '/':

            startTime = datetime.datetime.utcnow()
            if len(currentStageName) == 0:
                stages = {"planet": parseSteps("planet")}
            else:
                stages = {currentStageName: parseSteps(currentStageName)}
            for x in stages:
                stage = stages[x]
            while True:
                if stage.nextStageName:
                    # I know this creates a race condition, I just don't care
                    threading.Thread(target=loadNext,
                                     args=(stages,
                                           stage.nextStageName)).start()
                currentStep = 0
                delay = False
                currentStageName = stage.name
                stepList = stage.steps
                newStepList = []
                for idx, x in enumerate(stepList):
                    replayStep(x)
                    newStepList.append(x)
                print("done: " + currentStageName)
                for i, step in enumerate(newStepList):
                    if step.output == OutputType.MOVE:
                        if newStepList[
                                i +
                                1].output == OutputType.CLICK or newStepList[
                                    i + 1].output == OutputType.LONG_CLICK:
                            stepImage = step.imageName
                            nextStep = newStepList[i + 1]
                            nextStepImage = nextStep.imageName
                            step.imageName = nextStepImage
                            nextStep.imageName = stepImage
                f = open(currentStageName + ".dat", "w")
                stage = formatStage(Stage(currentStageName, newStepList))
                f.write(stage)

                han = win32api.OpenProcess(
                    win32con.PROCESS_QUERY_INFORMATION
                    | win32con.PROCESS_VM_READ, 0, os.getpid())
                process_memory = int(
                    win32process.GetProcessMemoryInfo(han)['WorkingSetSize'])
                print("memory:" + str(process_memory))
                nextStageName = stages[currentStageName].nextStageName
                stage = stages[nextStageName]
                if nextStageName is None:
                    break
コード例 #2
0
import os

import cv2
import numpy as np
from matplotlib import pyplot as plt

from step import parseSteps, OutputType

template = cv2.imread('arrowUp.bmp', cv2.IMREAD_COLOR)
d, w, h = template.shape[::-1]

# All the 6 methods for comparison in a list
meth = 'cv2.TM_CCORR_NORMED'

method = eval(meth)

listdir = os.listdir(".")
for file in listdir:
    if file.endswith(".dat"):
        stage = parseSteps(file.replace(".dat", ""))
        for step in stage.steps:
            if step.output == OutputType.CLICK and step.imageName:
                img = cv2.imread(step.imageName, cv2.IMREAD_COLOR)
                res = cv2.matchTemplate(img, template, method)
                min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)
                if max_val > 0.85:
                    print("Hit on: " + step.imageName)
コード例 #3
0
ファイル: cleanup.py プロジェクト: Raptoer/HypeTas
from PIL import Image

import step

list = os.listdir(".")
for i in list:
    if i.endswith(".dat"):
        dir = i.replace(".dat", "")
        allFiles = os.listdir(dir + "\\")
        for f in allFiles:
            if f.endswith(".bmp"):
                Image.open(dir + "\\" + f).save(
                    dir + "\\" + f.replace(".bmp", ".png"), "png")
                os.remove(dir + "\\" + f)

list = os.listdir(".")
for i in list:
    if i.endswith(".dat"):
        stage = step.parseSteps(i.replace(".dat", ""))
        files = [
            re.sub(".*?\\\\", "", s.imageName) for s in stage.steps
            if s.imageName is not None
        ]
        dir = stage.name
        print(files)
        print(dir)
        allFiles = os.listdir(dir + "\\")
        for f in allFiles:
            if f not in files:
                os.remove(dir + "\\" + f)
コード例 #4
0
def loadNext(stages, nextStageName):
    stages[nextStageName] = parseSteps(nextStageName)
コード例 #5
0
ファイル: recorder.py プロジェクト: Raptoer/HypeTas
def on_release(key):
    # I'm somewhat embarassed by how many global variables I use here
    global ctrlOn
    global currentStageName
    global currentStep
    global stepList
    global stage
    global clickImage
    global append
    global delay
    global override
    global startTime
    global listen
    if not listen:
        return
    if hasattr(key, "name"):
        if key.name == 'ctrl_l':
            ctrlOn = False
        if key.name == 'tab':
            resetMouse()
            recordWalk(OutputType.RESET, None)
        if key.name == 'space':
            if not clickImage:
                clickImage = loopAndGrabImage()
            # save ref image and record click
            mouse.press(Button.left)
            time.sleep(0.05)
            mouse.release(Button.left)
            clickImageTemp = clickImage
            clickImage = False
            recordWalk(OutputType.CLICK, clickImageTemp,
                       [currentMov[0], currentMov[1]])
            if ctrlOn:
                loopUntilChange()
                clickImage = loopAndGrabImage()
        if key.name == 'insert':
            if not clickImage:
                clickImage = loopAndGrabImage()
            # save ref image and record click
            keyboard.press(Key.enter)
            keyboard.release(Key.enter)
            clickImageTemp = clickImage
            clickImage = False
            recordWalk(OutputType.ENTER, clickImageTemp)
            if ctrlOn:
                clickImage = loopUntilChange()
                mouse.press(Button.left)
                time.sleep(0.05)
                mouse.release(Button.left)
                clickImageTemp = clickImage
                clickImage = False
                recordWalk(OutputType.CLICK, clickImageTemp,
                           [currentMov[0], currentMov[1]])

    if hasattr(key, "char"):
        amt = 50
        if ctrlOn:
            amt = 5
        if key.char == 'f':
            moveMouse(0, amt, True)
        if key.char == 'g':
            moveMouse(amt, 0, True)
        if key.char == 'r':
            moveMouse(0, -amt, True)
        if key.char == 'd':
            moveMouse(-amt, 0, True)
        if key.char == 'i':
            if ctrlOn:
                loopAndPress(OutputType.PG_UP)
            else:
                loopAndPress(OutputType.UP)
        if key.char == 'j':
            if ctrlOn:
                loopAndPress(OutputType.HOME)
            else:
                loopAndPress(OutputType.LEFT)
        if key.char == 'k':
            if ctrlOn:
                loopAndPress(OutputType.PG_DOWN)
            else:
                loopAndPress(OutputType.DOWN)
        if key.char == 'l':
            if ctrlOn:
                loopAndPress(OutputType.END)
            else:
                loopAndPress(OutputType.RIGHT)
        if key.char == ';':
            for idx, x in enumerate(stepList):
                replayStep(x)
            print("done: " + currentStageName)
            delay = False
            if stage.nextStageName is None:
                print("ready to read")
                if not append:
                    stage = None
                    stepList = []
                    currentStep = 0
                    currentStageName = ""
            else:
                stage = parseSteps(stage.nextStageName)
                currentStep = 1
                currentStageName = stage.name
                print("ready: " + stage.name)
                stepList = stage.steps
        if key.char == '/':
            startTime = datetime.datetime.utcnow()
            if len(currentStageName) == 0:
                stages = {"d2": parseSteps("d2")}
            else:
                stages = {currentStageName: parseSteps(currentStageName)}
            for x in stages:
                stage = stages[x]
            while True:
                if stage.nextStageName:
                    # I know this creates a race condition, I just don't care
                    threading.Thread(target=loadNext,
                                     args=(stages,
                                           stage.nextStageName)).start()
                currentStep = 0
                delay = False
                currentStageName = stage.name
                stepList = stage.steps
                for idx, x in enumerate(stepList):
                    replayStep(x)
                print("done: " + currentStageName)
                process = psutil.Process(os.getpid())
                print(process.memory_info().rss)
                if stages[currentStageName].nextStageName is None:
                    break
                stage = stages[stages[currentStageName].nextStageName]
                # currentStageName is actually the previous stage's name here
                stages.pop(currentStageName)

        if key.char == '\'':
            replayStep(stepList[currentStep])
            print("done: " + str(currentStep))
        if key.char == 'z':
            preImage = loopAndGrabImage()
            keyboard.press(Key.f7)
            keyboard.release(Key.f7)
            keyboard.press(Key.f8)
            keyboard.release(Key.f8)
            recordWalk(OutputType.ANIM_OFF, preImage)
        if key.char == '[':
            # start playback
            if currentStageName != '' and not override:
                override = True
                print(
                    "warning, already loaded, did you mean to press record instead? Pressing again will override"
                )
            else:
                currentStageName = input('which stage?')
                stage = parseSteps(currentStageName)
                stepList = stage.steps
        if key.char == ']':
            append = not append
            if append:
                print("Mode: append")
            else:
                print("Mode: new")
        if key.char == 'p':
            # stop recording
            currentStageName = input('stage name:')
            f = open(currentStageName + ".dat", "w")
            for step in stepList:
                if step.imageName is not None:
                    step.imageName = step.imageName.replace(
                        "\\\\", "\\" + currentStageName + "\\")
            stage = formatStage(Stage(currentStageName, stepList))
            print(stage)
            f.write(stage)
            moveImages(currentStageName)