网友回复
先看看代码:
# -*- enoding:utf-8 -*- # 生成 buffer 对象 import win32con from win32gui import PyMakeBuffer, SendMessage, PyGetBufferAddressAndLen, PyGetString length = 10000 # hWnd=68214这个是句柄值 hWnd=68302 buf = PyMakeBuffer(length) length2 = SendMessage(hWnd, win32con.WM_GETTEXT, length, buf)+1 print(length2) buf = PyMakeBuffer(length2) print('get: ', SendMessage(hWnd, win32con.WM_GETTEXT, length2, buf)) address, length = PyGetBufferAddressAndLen(buf) text = PyGetString(address, length) print('text: ', text)
所使用模块主要是win32gui与win32con
其他窗口操作api
引入模块
import win32gui import win32con import win32api import psutil import win32process
获取当前【鼠标坐标】
# 获取当前鼠标【x y】坐标
point = win32api.GetCursorPos()
通过鼠标坐标 获取鼠标坐标下的【窗口句柄】
# 通过坐标获取坐标下的【窗口句柄】 hwnd = win32gui.WindowFromPoint(x,y) # 请填写 x 和 y 坐标
通过窗口句柄获取 【线程ID 和 进程ID】
# 通过句柄获取【线程ID 进程ID】 hread_id, process_id = win32process.GetWindowThreadProcessId('句柄值')
通过进程ID 获取【进程名称】
# 通过进程ID获取【进程名称】 列:weixin.exe process = psutil.Process('进程ID').name()
通过进程ID 获取【标准路径】
# 通过进程ID 获取主文件程序【标准路径】 列:D:/filed/windoee/weixin.exe p_bin = psutil.Process('进程ID').exe()
通过进程ID 获取当前程序的【CPU利用率...
点击查看剩余70%
python如何将2d平面线图转换成数字2d线稿图?
acejs代码编辑器如何调用openai api实现选择代码修改与代码自动补全?
ace.js如何获取选择文本的开始和结束行数?
如何把qwen code cli或gemini cli的免费调用额度换成http api对外开放接口?
如何限制windows10电脑只能打开指定的程序?
python如何调用ai大模型实现web网页系统的功能测试并生成测试报告?
有没有免费进行web网站ai仿真人测试生成测试报告的mcp服务或api?
Context Engineering到底是啥,有什么用?
如何使用Google veo 3+高斯溅射(Gaussian Splatting)技术生成4d视频?
浏览器中如何实时调用摄像头扫描二维码?