python win32api.shellexecute_socket send函数
记事本的主窗口中还有一个窗口,您需要向它发送消息。您可以使用Microsoft Spy++工具查看此“隐藏”窗口,也可以获取所有子窗口,如下所示:def callback(hwnd, hwnds):
if win32gui.IsWindowVisible(hwnd) and win32gui.IsWindowEnabled(hwnd):
hwnds[win32gui.GetClassName(hwnd)] = hwnd
return True
hwnds = {}
win32gui.EnumChildWindows(whndl, callback, hwnds)
我们正在查找的窗口具有“Edit”类名,它是记事本唯一启用且可见的子窗口。所以你的代码是这样工作的:import win32api, win32con, win32gui, win32ui, win32service, os, time
def f_click(pycwnd):
x=300
y=300
lParam = y <<15 | x
pycwnd.SendMessage(win32con.WM_LBUTTONDOWN, win32con.MK_LBUTTON, lParam);
pycwnd.SendMessage(win32con.WM_LBUTTONUP, 0, lParam);
def get_whndl():
whndl = win32gui.FindWindowEx(0, 0, None, ‘NB.txt – Notepad’)
return whndl
def make_pycwnd(hwnd):
PyCWnd = win32ui.CreateWindowFromHandle(hwnd)
return PyCWnd
def send_input_hax(pycwnd, msg):
f_click(pycwnd)
for c in msg:
if c == “\n”:
pycwnd.SendMessage(win32con.WM_KEYDOWN, win32con.VK_RETURN, 0)
pycwnd.SendMessage(win32con.WM_KEYUP, win32con.VK_RETURN, 0)
else:
pycwnd.SendMessage(win32con.WM_CHAR, ord(c), 0)
pycwnd.UpdateWindow()
whndl = get_whndl()
def callback(hwnd, hwnds):
if win32gui.IsWindowVisible(hwnd) and win32gui.IsWindowEnabled(hwnd):
hwnds[win32gui.GetClassName(hwnd)] = hwnd
return True
hwnds = {}
win32gui.EnumChildWindows(whndl, callback, hwnds)
whndl = hwnds[‘Edit’]
pycwnd = make_pycwnd(whndl)
msg = “It works !\n”
send_input_hax(pycwnd,msg)
lParam是int,您在这里看到的技巧是允许您通过一个参数传递多个值。假设我们需要将两个数字传递给只接受一个参数的函数。我们可以将它们作为两位数发送,并在函数中进行拆分。同样,按位移位(<;<;)和按位或(|)操作在您的情况下也可以反转:>>> x = 300
>>> y = 300
>>> lParam = y << 15 | x
>>> lParam & 0x7FFF # x
0: 300
>>> lParam >> 15 # y
1: 300
您可以在Wikipedia和Python Wiki中阅读有关按位操作的更多信息。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/183175.html原文链接:https://javaforall.cn
相关文章
- python电脑版微信-微信PC版的API接口 | 可通过Python调用微信功能
- python爬虫—–Python访问http的几种方式「建议收藏」
- python socket recvfrom_Python:socket.recvfrom()不返回任何地址
- python基础(7)内置函数divmod用法
- python setattr函数_Python内置函数(53)——setattr
- 【说站】python偏函数如何理解
- Python标识符的命名规则,下列哪些是对的?_python标识符不能使用关键字
- python图像多层小波分解_Python中图像小波分解与重构以及灰度图加噪
- python抛出异常和捕获异常_Python异常
- Python将数据写入txt文件_python将内容写入txt文件
- Python语法之函数
- python画素描画
- Python基础语法-函数-高阶函数(二)
- Python 七种邮件内容发送方法实例详解编程语言
- python中一些内置函数实例详解编程语言
- 学习Python精通SQL Server操作技巧(python操作sqlserver)
- Python操作Redis实现数据持久化(python操作redis)
- Python的lambda匿名函数的简单介绍