python - 在 Python 中通过 windows api 将键盘输入发送到 Notepad++
问题描述
我知道并非所有 Windows 都处理键盘输入这一事实。但是,我的 Notepad++ 树的一个窗口应该对编辑器产生影响,即写下我要发送的“A”。我已经尝试了所有子窗口,但没有任何效果:
def mycallback(hwnd, data):
data[hwnd] = win32gui.GetClassName(hwnd)
win32gui.EnumChildWindows(hwnd, mycallback, data)
return True
mywindows = {}
win32gui.EnumChildWindows(197788, mycallback, mywindows) # 197788 is the notepad++ handle whose parent is 0
# at this point, mywindows contains: {'#32770': 66908, 'Button': 66922, 'Static': 66924, 'SysTabControl32': 132272, 'Scintilla': 132276, 'splitterContainer': 263444, 'wespliter': 328982, 'msctls_statusbar32': 394476, 'dockingManager': 394474, 'wedockspliter': 132328, 'nsdockspliter': 132336, 'ReBarWindow32': 66906, 'ToolbarWindow32': 66902, 'Edit': 66914}
for v in mywindows.values():
win32api.SendMessage(v, win32con.WM_CHAR, 0x41, 0) # trying to send an 'A' to notepad++ without knowing to which window I need to send it to. I had already noticed before that sending the 'A' to the "Edit" window doesn't work (the EXACT same win32api.SendMessage command works for the "Edit" window of the Microsoft-Windows-notepad-editor by the way)
# the return values of this loop are: 0,0,0,0,0,0,0,0,0,0,0,0,0,1
只有“编辑”窗口返回 1。1 表示错误,所以我假设“编辑”是正确的目标窗口,但为什么它返回错误?
顺便说一句:Microsoft-Windows-notepad-editor 的“编辑”窗口也返回 1,但它会将“A”打印到编辑器。
解决方案
推荐阅读
- java - Spring AOP:代表类型声明其他方法或字段
- javascript - 防止 Ramda.omit 将数组转换为对象
- cuda - 如何将内联 PTX 插入 OpenMP 代码?就像我们可以在 Nvidia PTX Assembly 的 CUDA 代码中做的那样?
- javascript - Rollup Javascript API:rollup.watch 进程永不消亡
- angular - 在Angular中重新加载页面后如何保持在同一页面
- url-rewriting - 如何在lucee中实现urlrewrite
- javascript - 如何将 JavaScript 构造函数对象作为 IFFI 函数参数访问?
- ios - Ant Media Server 的 iOS 框架不被 App Store 接受?
- bash - 使用正则表达式进行密码验证在我的 shell 脚本中不起作用
- javascript - 为什么在分配之前,console.log中的js对象不为空?