我没有从列表中选择一个项目(使用代码波纹管),我现在需要发送一个ctrl+E
。问题是,SendKeys方法isn't available,我不能使用SendKeys('^e')
。 (此快捷方式将在同上应用程式编辑所选择的项目)pywinauto:如何SendKeys不接受SendKeys的ListView?
from pywinauto.application import Application
from pywinauto import findbestmatch
from pywinauto import keyboard #not sure if I need to import it
ditto=Application().connect(path='Ditto.exe')
#---- print all available methods of the object
print(dir(ditto.ditto.SysListView321.wrapper_object())) #(the list does not contains 'SendKeys')
#-----Find and select the item (containing 'xxx') in the SysListView321
#The list of texts to search through
texts = ditto.ditto.SysListView321.texts()[1:] #skip window text itself, use only item texts
# The list of items corresponding (1 to 1) to the list of texts to search through.
items = ditto.ditto.SysListView321.items() #>>[]
found_item = findbestmatch.find_best_match('xxx', texts, items, limit_ratio=0.1).Select()
一些错误:
ditto.ditto.SysListView321.SendKeys('^e')
... WindowSpecification class has no 'SendKeys' method
ditto.ditto.SysListView321.keyboard.SendKeys('^e')
... findbestmatch.MatchError: Could not find 'keyboard' in 'dict_keys(['', 'Header'])'
[编辑](更多错误)
ditto.ditto.SysListView321.type_keys('^e')
win32gui.SetForegroundWindow(self.handle) pywintypes.error: (0, 'SetForegroundWindow', 'No error message is available')
keyboard.send_keys('^e')
AttributeError: module 'pywinauto.keyboard' has no attribute 'send_keys'
(诗。对于初学者:app.Ditto
相当于app.window(best_match='Ditto')
)
谢谢!关于我的问题,你的解决方案没有任何工作(但它越来越好!)。我在我的问题编辑中添加了新的控制台错误。 ditto.ditto.SysListView321.type_keys('^ e')并不遥远:如果我在同一时间多次点击同上窗口,我会启动代码,它会起作用。所以它似乎是一个活动窗口的问题。脚本在同上列表中选择一个项目,但在type_keys('^ e')期间似乎失去焦点。 –
我不明白你使用'.keyboard'的意思:我使用'keyboard.SendKeys'与我使用'findbestmatch.find_best_match'(用于访问类中的方法)相同的方式。 'SendKey's是'keyboard'类的一种方法吗?键盘是一个模块和键盘吧?如果是这样,为什么不把它们作为python调用呢:'class.method'? http://pywinauto.readthedocs.io/en/latest/code/code.html#main-user-modules –
“keyboard”是一个模块,它不是另一个类的成员。你有没有使用其他编程语言的类? –