mirror of
https://github.com/yuruotong1/autoMate.git
synced 2026-03-22 13:07:17 +08:00
🚀 部署(test_path.py): 添加test_window函数,测试并获取当前活动窗口的标题 🔧 添加(window_util.py): 引入WindowUtil类,获取当前活动窗口的标题。
31 lines
752 B
Python
31 lines
752 B
Python
import os
|
|
import time
|
|
|
|
|
|
def test_path():
|
|
desktop_path = r"C:\Users\yuruo\Desktop"
|
|
file_list = []
|
|
for dirpath, dirnames, filenames in os.walk(desktop_path):
|
|
for filename in filenames:
|
|
file_list.append(os.path.join(dirpath, filename))
|
|
print(file_list)
|
|
|
|
def test_window():
|
|
import ctypes
|
|
# 获取当前活动窗口的句柄
|
|
hWnd = ctypes.windll.user32.GetForegroundWindow()
|
|
|
|
# 获取窗口标题
|
|
length = ctypes.c_int(256)
|
|
buffer = ctypes.create_unicode_buffer(length.value)
|
|
ctypes.windll.user32.GetWindowTextW(hWnd, buffer, length)
|
|
title = buffer.value.split("-")[-1]
|
|
|
|
print(title)
|
|
|
|
if __name__ == "__main__":
|
|
while True:
|
|
test_window()
|
|
time.sleep(2)
|
|
|