gpt4 book ai didi

linux - 绑定(bind)到 Linux 系统事件?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:41:31 25 4
gpt4 key购买 nike

对于 Linux,有一个名为 xbindkeys 的漂亮的小库,它(惊喜)将您选择的命令绑定(bind)到某些组合键。

我正在寻找类似的东西,除了系统硬件事件。当我将耳机插入计算机的输出插孔时,我希望能够调用程序。当我拔下耳机时能够绑定(bind)到事件也很好。

有人知道这是否可行吗?也许通过一些很酷的 Python X11 库?

提前致谢。

编辑:找到 jack 抽象层的 API:http://www.alsa-project.org/~tiwai/alsa-driver-api/ch06s02.html遗憾的是,这只允许轮询设备,而不是事件处理程序。

最佳答案

你可能想为此使用 udev。我没有使用过 libudev,但这是 something I found :

libudev - Monitoring Interface

libudev also provides a monitoring interface. The monitoring interface will report events to the application when the status of a device changes. This is useful for receiving notification when devices are connected or disconnected from the system.

操作以下列字符串形式返回:

  • add - Device is connected to the system
  • remove - Device is disconnected from the system
  • change - Something about the device changed
  • move - Device node was moved, renamed, or re-parented

那篇文章接着展示了它如何通过 udev_monitor_get_fd 获取文件描述符,然后通过 select 对其进行监控。

关于linux - 绑定(bind)到 Linux 系统事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8441333/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com