我想记录一个 Windows 应用程序的用户场景。为此,我想在鼠标单击屏幕截图旁边的对象和鼠标位置后检索/记录 GUI 对象的对象类型、对象名称和对象值。
我一直在寻找如何做。请帮忙。
我有以下 Python 代码。
saveDir = r'C:\Privat\ZuppU\temp'
stepListID = 1
def capture_step_objects(event):
global stepListID
stepEvent = 'Click'
# Capture the application mouseclick area
(mx, my) = event.Position
fgWindow = win32gui.GetForegroundWindow()
fgWindowName = win32gui.GetWindowText(fgWindow)
# Capture the application window
(ax1, ay1, ax2, ay2) = win32gui.GetWindowRect(fgWindow)
stepCapture = ImageGrab.grab((ax1, ay1, ax2, ay2))
stepImage = os.path.join(saveDir, 'Step' + str(stepListID) + '.png')
stepCapture.save(stepImage)
hm = pyHook.HookManager()
hm.SubscribeMouseAllButtonsDown(capture_step_objects)
hm.HookMouse()
pythoncom.PumpMessages()
hm.UnhookMouse()
# Main loop