from PIL import ImageGrab

for proc in psutil.process_iter(): try: if proc.name() == "大家来找茬.exe": pid = proc.pid hwnd = 0 for h in proc.get_hwnds(): if h > 0: hwnd = h break if hwnd > 0: rect = psutil.Process(pid).memory_maps()[0].get_memory_mapped_file_region().get_rect() img = ImageGrab.grab(bbox=(rect.left, rect.top, rect.right, rect.bottom)) img.save(os.getcwd() + "\found_it.png") break except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess): pass


这段代码会遍历所有正在运行的进程,如果找到了进程名为“大家来找茬”的进程,就会通过pid获取该进程的hwnd,然后通过hwnd获取该进程的窗口大小,并使用Pillow库中的ImageGrab模块获取该窗口的截图,最后将截图保存为found_it.png文件
human 用python获取windows进程名为大家来找茬的截图; AI 以下是使用Python获取Windows进程名为大家来找茬的截图的代码示例:pythonimport psutilimport os

原文地址: https://www.cveoy.top/t/topic/czS0 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录