Code Monkey home page Code Monkey logo

Comments (3)

shanelecuyer avatar shanelecuyer commented on May 21, 2024 1

well im not quite happy with it yet... im still very new and the code is a mess. storing variables in a Dict is not ideal. had to make many workarounds due to that, i will learn to store them as objects and create a thread class also... but for now, this works (i can easily run 30+ oldschool runescape clients with a little mitm server intercepting the jav_config.ws http request to avoid advertisement errors... anyway, if you want to help me make this better... PLEASE DO

    def getScreen (self, account):
        #loop_time = time()
        t = threading.currentThread()
        while getattr(t, "loop", True):
            if account in procDict and procDict[account]['hwnd']:
                hwnd = procDict[account]['hwnd'][0]
                screenshot = wincap.get_screenshot(hwnd)
                if screenshot is not None:
                    cv.imshow(f'{account} screenshot', screenshot)
                    cv.waitKey(1)
            #print('FPS {}'.format(1 / (time() - loop_time)))
            #loop_time = time()
            sleep(.1)
            
    def cvLoop (self):
        global cvLoop
        while(cvLoop):
            windowVal = "Not Found"
            for account in list(procDict):
                if account in procDict and procDict[account]['dur'] and procDict[account]['proc']:
                    pid = procDict[account]['proc'].pid
                    hwnd = findWin(pid)
                    procDict[account]['hwnd'] = hwnd
                    if hwnd:
                        windowVal = hwnd
                        if not win32gui.IsWindow(hwnd[0]) or not win32gui.IsWindowVisible(hwnd[0]):
                            print('fucked up')
                            procDict[account]['hwnd'] = None
                        else:
                            if not account in threadNames():
                                t = Thread(target=self.getScreen, args=(account, ), daemon=True)
                                t.name = account
                                t.start()
                    else:
                        for killThread in threading.enumerate():
                            if killThread.name == account:
                                killThread.loop = False
                        cv.destroyWindow(f'{account} screenshot')
                for row in self.tv.treeview.get_children():
                    if self.tv.treeview.item(row,'text') == account:
                        self.tv.treeview.set(row, 'hwnd', windowVal)
            sleep(.5)

from opencv_tutorials.

learncodebygaming avatar learncodebygaming commented on May 21, 2024

Thanks for the info Shane, I'll definitely check that out! Glad these videos have been helpful for you. And feel free to share that game window finder code when you're happy with it. I'm sure it could help somebody else out, too.

from opencv_tutorials.

shanelecuyer avatar shanelecuyer commented on May 21, 2024
def findWin (pid):
    def callback (hwnd, hwnds):
        if win32gui.IsWindowVisible (hwnd) and win32gui.IsWindowEnabled (hwnd):
            _, found_pid = win32process.GetWindowThreadProcessId (hwnd)
            if found_pid == pid:
                hwnds.append(hwnd)
                return True

    hwnds = []
    win32gui.EnumWindows (callback, hwnds)
    return hwnds

from opencv_tutorials.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.