python - Python - 如何捕获 Windows 通知按钮按下事件
问题描述
问题总结
我最近使用该winrt
模块成功地使用 Python 显示本机 Windows 通知。但是,我无法弄清楚如何在这些通知中检测按钮按下事件。所以我的主要问题是:如何使用 Python捕获winrt
通知事件(尤其是)?ToastNotification.Activated
我已经发现或做过的事情
我在 winrt GitHub 页面上找到了一个代码片段asyncio
,它使用该模块来捕获某个蓝牙事件。我尝试将其修改为使用 windows ToastNotification
,但由于这是我第一次使用 asyncio 和 winrt,很遗憾我没有成功。我相信我想要捕捉的确切事件是ToastNotification.Activated
(此处的文档)。
以前,我也尝试过使用 和 之类的通知模块zroya
,win10toast
但由于这些模块非常有限,我决定尝试直接winrt
方法以在布局中获得更多自由。
我的代码显示原生 Windows 通知,按钮还没有做任何事情,是
from winrt.windows.ui.notifications import ToastNotificationManager, ToastNotification
import winrt.windows.data.xml.dom as dom
# AppID is just an example here, it can be retrieved using the Powershell command "get-StartApps"
AppID = "{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\\WindowsPowerShell\\v1.0\\powershell.exe"
nManager = ToastNotificationManager
notifier = nManager.create_toast_notifier(AppID)
tString = r"""
<toast>
<visual>
<binding template='ToastGeneric'>
<text>This is the toast title.</text>
<text>This is the 1st line.</text>
<text>Surprisingly, this is the 2nd line!</text>
<text placement="attribution">This text is kinda smol :)</text>
</binding>
</visual>
<actions>
<action content="Dismiss" arguments="action=dismiss" />
<action content="More info" arguments="action=moreinfo" />
<action content="Watch live" arguments="action=watchlive"/>
</actions>
</toast>
"""
xDoc = dom.XmlDocument()
xDoc.load_xml(tString)
notification = ToastNotification(xDoc)
notifier.show(notification)
我也不确定arguments="action=dismiss"
etc. 做了什么,虽然我还没有详细研究这些论点,但我想它们与事件有关。如果你能在这个问题上启发我,我提前谢谢你:)
解决方案
推荐阅读
- excel - 当成员是 Cubset 函数时,Cubevalue 返回空白(零长度字符串)
- javascript - 将代码移动到导出的函数会导致 TypeError:将循环结构转换为 JSON
- python - 使用 PyOpenGL 和 PyQt5 制作 Sphere 的问题
- dotnetnuke - DotNetNuke 9 中最佳实践 MVC 模块示例
- javascript - 如何撤消“this.onclick=null”?如何将javascript onclick功能恢复到div?
- java - Android Searchview在使用ListView点击项目时过滤错误
- amazon-web-services - 传输 Amazon EC2 实例时主机名和 IP 地址发生变化
- c++ - constexpr:gcc 比 clang 更努力地评估 constexpr
- ffmpeg - ffmpeg 提取帧并根据 exif 或 txt 中每个提取帧的创建时间获取时间戳
- angular - Angular Material MatPaginator 无法翻译