Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 创建一个扑克桌扫描器_Python_Ui Automation_Poker - Fatal编程技术网

Python 创建一个扑克桌扫描器

Python 创建一个扑克桌扫描器,python,ui-automation,poker,Python,Ui Automation,Poker,我正在尝试为pokerstars()软件构建一个表扫描程序 软件如下所示: 软件感兴趣的两个部分以橙色突出显示。左侧部分是所有表外名称,右侧部分是当前活动表外的玩家名称 稍后我将调用左侧部分tableView,右侧部分playerView 在表格视图上,您可以选择要查看的表格。然后,您可以在playerView中看到所有玩家都坐在那张桌子旁。我想检索的基本上是一个二维数组: [ { "table": "Aeria IV", "players": [

我正在尝试为pokerstars()软件构建一个表扫描程序

软件如下所示:

软件感兴趣的两个部分以橙色突出显示。左侧部分是所有表外名称,右侧部分是当前活动表外的玩家名称

稍后我将调用左侧部分
tableView
,右侧部分
playerView

表格视图
上,您可以选择要查看的表格。然后,您可以在
playerView
中看到所有玩家都坐在那张桌子旁。我想检索的基本上是一个二维数组:

[
    {
        "table": "Aeria IV",
        "players": [
            "careu82",
            "Noir_D€sir",
            "Onyon666",
            "plz542",
            "pripri17",
            "yataaaaaaaa"
        ]
    },
    {
        "table": "Aase III"
            "players":[...]
    },
    ...
]
为了实现这一点,我设想了以下我想要自动化的过程:

  • 上移到
    表格视图中的第一个表格
  • 等待该表的玩家名称显示在
    playerView
  • tableView
    中检索表名,在
    playerView
  • tableView
  • 执行(2.)操作,除非我们到达了结束点
    tableView
  • 到目前为止,我制作的程序使用UIAutomation

    它解析所有打开的窗口(Chrome、paint、Pokerstars软件),以找到标题包含“Lobble”的窗口。这是函数
    forEachWindow
    的作用

    对于包含大厅的窗口,它将查看所有UI元素
    forEachUIElement
    。我现在正在检索pokerstars窗口的childcontent视图:
    iuia.controlViewWalker.GetFirstChildElement(starsWindow)
    ,使用
    uiElement.CurrentBoundingRectangle
    存储它们的位置、宽度和高度,并使用
    uiElement.CurrentClassName
    存储它们的类名

    然后,我将创建与UIElements具有相同宽度/位置的白色窗口,以查看哪个元素在哪里

    如您所见,这两个有趣的元素属于class
    PokerStarsListClass

    执行所有这些操作的代码如下所示:

    from PyQt4.QtGui import *
    from PyQt4.QtCore import *
    from PyQt4.QtWebKit import *
    import sys ,comtypes
    from comtypes import *
    from comtypes.client import *
    
    # Generate and import a wrapper module for the UI Automation type library,
    # using UIAutomationCore.dll
    comtypes.client.GetModule('UIAutomationCore.dll')
    from comtypes.gen.UIAutomationClient import *
    
    # Instantiate the CUIAutomation object and get the global IUIAutomation pointer:
    iuia = CoCreateInstance(CUIAutomation._reg_clsid_,
                            interface=IUIAutomation,
                            clsctx=CLSCTX_INPROC_SERVER)
    
    rawView=iuia.rawViewWalker
    controlView=iuia.controlViewWalker
    
    
    def forEachUIElement(content_element,searchedClass=""):
        list=[]
        uiElement=controlView.GetFirstChildElement(content_element)
        while(uiElement!=None):
            try:
                rectangle=uiElement.CurrentBoundingRectangle
                width=rectangle.right-rectangle.left
                height=rectangle.bottom-rectangle.top
                y= rectangle.top
                x= rectangle.left
                className=str(uiElement.CurrentClassName)
                print className
                if searchedClass in className:
                    list.append([uiElement,x,y,width,height,className])
            except Exception:
                ''
            try:
                uiElement=controlView.GetNextSiblingElement(uiElement)
            except Exception:
                uiElement=None
        print 'finish'
        return list
    
    def forEachWindow(root_element):
        window=rawView.GetFirstChildElement(root_element)
        while(window!=None):
            try:
                windowName=window.currentName
                if 'Lobby' in windowName:
                    print 'found'+windowName
                    uiElements=forEachUIElement(window)
            except Exception:
                ''
            try:
                window=rawView.GetNextSiblingElement(window)
            except Exception:
                window=None
        return uiElements
    
    
    class WindowOverLayer(QWebView):
        def __init__(self,parent):
            super(WindowOverLayer, self).__init__()
            self.parent=parent
            self.show()
        def closeEvent(self,event):
            self.parent.quit()
    
    desktop = iuia.getRootElement()
    uiElements=forEachWindow(desktop)
    app=QApplication(sys.argv)
    windowOverLayers=[]
    for uiElement in uiElements:
        content= str(uiElement[5])
        windowOverLayer= WindowOverLayer(app)
        windowOverLayer.resize(uiElement[3],uiElement[4])
        windowOverLayer.move(uiElement[1],uiElement[2])
        windowOverLayer.setHtml(content)
        windowOverLayers.append(windowOverLayer)
    
    app.exec_()
    
    既然我现在可以选择属于类
    PokerStarsListClass
    的UIElements,并假设这两个元素存储在
    tableView
    playerView
    中,那么我该如何自动化该过程

    以下是有关使用内容属性的
    tableView
    的更多信息:

    CurrentAcceleratorKey: 
    CurrentAccessKey: 
    CurrentAriaProperties: 
    CurrentAriaRole: 
    CurrentAutomationId: 
    CurrentBoundingRectangle: <ctypes.wintypes.RECT object at 0x00000000037A2948>
    CurrentClassName: PokerStarsListClass
    CurrentControlType: 50033
    CurrentControllerFor: <POINTER(IUIAutomationElementArray) ptr=0x9466250 at 37a2948>
    CurrentCulture: 0
    CurrentDescribedBy: <POINTER(IUIAutomationElementArray) ptr=0x9466370 at 37a2948>
    CurrentFlowsTo: <POINTER(IUIAutomationElementArray) ptr=0x9466310 at 37a2948>
    CurrentFrameworkId: Win32
    CurrentHasKeyboardFocus: 0
    CurrentHelpText: 
    CurrentIsContentElement: 1
    CurrentIsControlElement: 1
    CurrentIsDataValidForForm: 0
    CurrentIsEnabled: 1
    CurrentIsKeyboardFocusable: 1
    CurrentIsOffscreen: 0
    CurrentIsPassword: 0
    CurrentIsRequiredForForm: 0
    CurrentItemStatus: 
    CurrentItemType: 
    CurrentLabeledBy: <POINTER(IUIAutomationElement) ptr=0x0 at 37a2948>
    CurrentLocalizedControlType: pane
    CurrentName: 
    CurrentNativeWindowHandle: 1574328
    CurrentOrientation: 0
    CurrentProcessId: 11300
    CurrentProviderDescription: [pid:6188,hwnd:0x1805B8 Main:Nested [pid:11300,hwnd:0x1805B8 Annotation(parent link):Microsoft: Annotation Proxy (unmanaged:uiautomationcore.dll); Main:Microsoft: MSAA Proxy (unmanaged:uiautomationcore.dll)]; Hwnd(parent link):Microsoft: HWND Proxy (unmanaged:uiautomationcore.dll)]
    
    CurrentAcceleratory:
    CurrentAccessKey:
    当前属性:
    当前角色:
    CurrentAutomationId:
    CurrentBoundingRectangle:
    CurrentClassName:PokerStarsListClass
    CurrentControlType:50033
    电流控制器:
    当前区域性:0
    当前描述人:
    当前流程至:
    CurrentFrameworkId:Win32
    CurrentHasKeyboardFocus:0
    当前帮助文本:
    CurrentIsContentElement:1
    当前控件:1
    CurrentIsDataValidForm:0
    当前已启用:1
    CurrentIsKeyboard可聚焦:1
    当前屏幕:0
    当前密码:0
    CurrentIsRequiredForForm:0
    当前项目状态:
    CurrentItemType:
    当前标签由:
    CurrentLocalizedControl类型:窗格
    当前名称:
    CurrentNativeWindowHandle:1574328
    当前方向:0
    CurrentProcessId:11300
    CurrentProviderDescription:[pid:6188,hwnd:0x1805B8主:嵌套[pid:11300,hwnd:0x1805B8注释(父链接):Microsoft:Annotation代理(非托管:uiautomationcore.dll);Main:Microsoft:MSAA代理(非托管:uiautomationcore.dll)];hwnd(父链接):Microsoft:hwnd代理(非托管:uiautomationcore.dll)]
    
    我看不出这个问题。你在挣扎什么?问题是:如果我可以选择相应的UIElement,我如何命令pokerstars软件在表列表中向上或向下移动?该列表是什么类型的控件?我如何检索该类型?我尝试了ItemType属性,但效果不好,我在这里有点不知所措。我的自动化程度不高。我想说,你需要把你的问题说得更清楚。我从两次阅读中都看不出来。