我正在尝试为软件扑克之星(this is totally legal)构建一个表扫描程序。
软件如下所示:
软件有趣的两个部分以橙色突出显示。左边的部分都是表格名称,右边部分是当前活动表格中的玩家名称。
稍后我会调用左侧部分tableView
和右侧部分playerView
在tableView
上,您可以选择要查看的表格。然后,您会看到playerView
中坐在该桌旁的所有玩家。我想要检索的基本上是一个二维数组:
[
{
"table": "Aeria IV",
"players": [
"careu82",
"Noir_D€sir",
"Onyon666",
"plz542",
"pripri17",
"yataaaaaaaa"
]
},
{
"table": "Aase III"
"players":[...]
},
...
]
为实现这一目标,我想到了以下我希望自动化的过程:
tableView
playerView
tableView
中的tableName和playerView
tableView
tableView
到目前为止,我制作的程序使用了UIAutomation。
它解析所有打开的窗口(Chrome,paint,Pokerstars软件),找到一个标题包含“Lobby”的窗口。这是函数forEachWindow
的作用。
对于包含Lobby的窗口,它将查看所有UI元素forEachUIElement
。我现在要检索pokerstars窗口的子内容视图:iuia.controlViewWalker.GetFirstChildElement(starsWindow)
,使用uiElement.CurrentBoundingRectangle
使用uiElement.CurrentClassName
及其className使用PokerStarsListClass
存储它们的位置和宽度和高度。
然后我创建了与UIElements具有相同宽度/位置的白色窗口,以查看哪个元素在哪里。
如您所见,两个有趣的元素属于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
鉴于我现在可以选择类tableView
的UIElements,并说这两个元素存储在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)]
的更多信息,使用内容属性:
{{1}}