简体   繁体   English

使用c ++库在Linux中注册热键

[英]Register hotkeys in Linux using library for c++

are there any libraries for Linux wrote with C++, that could register global hotkeys for my application? 有没有用C ++编写的Linux库,可以为我的应用程序注册全局热键? Thanks. 谢谢。

You'll have to provide more information. 您必须提供更多信息。

In Gnome, the global functionality varies by window manager. 在Gnome中,全局功能因窗口管理器而异。 Metacity has configurable global shortcuts, as do Compiz and Sawfish, and they're all configured differently. Metacity具有可配置的全局快捷方式,Compiz和Sawfish也是如此,它们的配置都不同。 Xhotkeys can also be used for the same functionality. Xhotkeys也可用于相同的功能。 However, these are all limited to starting applications only. 但是,这些仅限于启动应用程序。

Within the KDE application framework, KAction can register global shortcuts which perform actions inside your program. 在KDE应用程序框架内, KAction可以注册在程序内执行操作的全局快捷方式。 These are actually handled by a module in kded (launched on demand), so they work even outside of the KDE desktop environment. 这些实际上由kded中的模块(按需启动)处理,因此它们甚至可以在KDE桌面环境之外工作。

If you don't use the KDE framework, but are still using X11, you can use the xlib API to call XGrabKey on the root window. 如果您不使用KDE框架,但仍在使用X11,则可以使用xlib API在根窗口上调用XGrabKey

For shortcuts that work outside of X, as long as you are running as root (or permissions are changed permissively) on a 2.6 kernel, you can directly open /dev/input/event* , and poll for the desired key events. 对于在X之外工作的快捷方式,只要您在2.6内核上以root身份运行(或权限被允许更改),您就可以直接打开/dev/input/event* ,并轮询所需的键事件。

I wrote a simple C library a while back to make registering global X11 hotkeys a little less painful. 我一段时间写了一个简单的C库,使注册全局X11热键的痛苦少了一点。 There are some examples with the code. 代码中有一些例子。 You can get it at: 你可以在:

https://github.com/jwmcode/xhklib/ https://github.com/jwmcode/xhklib/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM