python读取类名Edit内容(插件自动化激活脚本开发)
这是孤狼在做Best Service混响R2R时遇到的一个问题,这个问题在孤狼备忘录上记录一下。起因是,Best Service是R2R版,用python做自动化要获取/读取R2R程序上Edit内容,用获取窗口句柄方式是空。如果不了解Best Service混响R2R激活步骤的去手动激活试试。python读取类名Edit内容后自动化操作就有可能成功。
在下面代码上单击左键,Ctrl+C复制。
import win32gui,win32api,win32con,ctypes obj = ctypes.WinDLL('user32.dll') Plugin_Alliance_4 = obj.FindWindowW("hspwnd0", "YellowTools E-License KeyGen v1.1.0") Plugin_Alliance_5 = obj.FindWindowExW(Plugin_Alliance_4, 0, "Edit", None) Plugin_Alliance_6 = obj.FindWindowExW(Plugin_Alliance_4, Plugin_Alliance_5, "Edit", None) length = win32gui.SendMessage(Plugin_Alliance_6, win32con.WM_GETTEXTLENGTH)+1 buf = win32gui.PyMakeBuffer(length) win32api.SendMessage(Plugin_Alliance_6, win32con.WM_GETTEXT, length, buf) address, length= win32gui.PyGetBufferAddressAndLen(buf[:-1]) text = win32gui.PyGetString(address, length) print(text)
import win32gui import win32con import win32api import ctypes length = win32gui.SendMessage(so_6_ke_3, win32con.WM_GETTEXTLENGTH) + 1 buf = ctypes.create_unicode_buffer(length) win32api.SendMessage(so_6_ke_3, win32con.WM_GETTEXT, length, buf) text = buf.value.encode("raw_unicode_escape").decode("gbk", errors="ignore") #text = buf.value #text = buf.value.encode("raw_unicode_escape").decode("utf-8", errors="ignore") print(text)