# QHotkey
A global shortcut/hotkey for Desktop Qt-Applications.
The QHotkey is a class that can be used to create hotkeys/global shortcuts, aka shortcuts that work everywhere, independent of the application state. This means your application can be active, inactive, minimized or not visible at all and still receive the shortcuts.
## Features
- Works on Windows, Mac and X11
- Easy to use, can use `QKeySequence` for easy shortcut input
- Supports almost all common keys (Depends on OS & Keyboard-Layout)
- Allows direct input of Key/Modifier-Combinations
- Supports multiple QHotkey-instances for the same shortcut (with optimisations)
- Thread-Safe - Can be used on all threads (See section Thread safety)
- Allows usage of native keycodes and modifiers, if needed
## Installation
The package is providet as qpm package, [`de.skycoder42.qhotkey`](https://www.qpm.io/packages/de.skycoder42.qhotkey/index.html). To install:
1. Install qpm (See [GitHub - Installing](https://github.com/Cutehacks/qpm/blob/master/README.md#installing), for **windows** see below)
2. In your projects root directory, run `qpm install de.skycoder42.qhotkey`
3. Include qpm to your project by adding `include(vendor/vendor.pri)` to your `.pro` file
Check their [GitHub - Usage for App Developers](https://github.com/Cutehacks/qpm/blob/master/README.md#usage-for-app-developers) to learn more about qpm.
**Important for Windows users:** QPM Version *0.10.0* (the one you can download on the website) is currently broken on windows! It's already fixed in master, but not released yet. Until a newer versions gets released, you can download the latest dev build from here:
- https://storage.googleapis.com/www.qpm.io/download/latest/windows_amd64/qpm.exe
- https://storage.googleapis.com/www.qpm.io/download/latest/windows_386/qpm.exe
## Usage
The general usage is to create QHotkey instances for specific hotkeys, register them and then simply connect to the signal emitted once the hotkey is pressed.
### Example
The following example shows a simple application that will run without a window in the background until you press the key-combination <kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>Q</kbd> (<kbd>⌘</kbd>+<kbd>⌥</kbd>+<kbd>Q</kbd> on Mac). This will quit the application. The debug output will tell if the hotkey was successfully registered and that it was pressed.
```cpp
#include <QHotkey>
#include <QApplication>
#include <QDebug>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QHotkey hotkey(QKeySequence("ctrl+alt+Q"), true);//The hotkey will be automatically registered
qDebug() << "Is Registered: " << hotkey.isRegistered();
QObject::connect(&hotkey, &QHotkey::activated, qApp, [&](){
qDebug() << "Hotkey Activated - the application will quit now";
qApp->quit();
});
return a.exec();
}
```
**Note:** You need the .pri include for this to work.
### Testing
By running the example in `./HotkeyTest` you can test out the QHotkey class. There are 4 sections:
- **Playground:** You can enter some sequences here and try it out with different key combinations.
- **Testings:** A list of selected hotkeys. Activate it and try out which ones work for you (*Hint:* Depending on OS and keyboard layout, it's very possible that a few don't work).
- **Threading:** Activate the checkbox to move 2 Hotkeys of the playground to seperate threads. It should work without a difference.
- **Native Shortcut**: Allows you to try out the direct usage of native shortcuts
### Logging
By default, QHotkey prints some warning messages if something goes wrong (For example, a key that cannot be translated). All messages of QHotkey are grouped into the [QLoggingCategory](https://doc.qt.io/qt-5/qloggingcategory.html) `"QHotkey"`. If you want to simply disable the logging, call the folling function somewhere in your code:
```cpp
QLoggingCategory::setFilterRules(QStringLiteral("QHotkey.warning=false"));
```
This will turn all warnings of QHotkey of (It only uses warnings for now, thats why this is enough). For more information about all the things you can do with the logging categories, check the Qt-Documentation
## Thread saftey
The QHotkey class itself is reentrant - wich means you can create as many instances as required on any thread. This allows you to use the QHotkey on all threads. **But** you should never use the QHotkey instance on a thread that is different from the one the instance belongs to! Internally the system uses a singleton instance that handles the hotkey events and distributes them to the QHotkey instances. This internal class is completley threadsafe.
However, this singleton instance only runs on the main thread. (One reason is that some of the OS-Functions are not thread safe). To make threaded hotkeys possible, the critical functions (registering/unregistering hotkeys and keytranslation) are all run on the mainthread too. The QHotkey instances on other threads use `QMetaObject::invokeMethod` with a `Qt::BlockingQueuedConnection`.
For you this means: QHotkey instances on other threads than the main thread may take a little longer to register/unregister/translate hotkeys, because they have to wait for the main thread to do this for them. **Important:** there is however, one additional limitation that comes with that feature: QHotkey instances on other threads but the main thread *must* be unregistered or destroyed *before* the main eventloop ends. Otherwise, your application will hangup on destruction of the hotkey. This limitation does not apply for instances on the main thread. Furthermore, the same happens if you change the shortcut or register/unregister before the loop started, until it actually starts.
## Documentation
The documentation is available as release and on [github pages](https://skycoder42.github.io/QHotkey/).
The documentation was created using [doxygen](http://www.doxygen.org). It includes an HTML-documentation and Qt-Help files that can be included into QtCreator (QtAssistant) to show F1-Help (See [Adding External Documentation](https://doc.qt.io/qtcreator/creator-help.html#adding-external-documentation) for more details).
## Technical
### Requirements
- I built it with Qt 5.7, but may work with earlier versions, too
- At least the QtGui-Module (a QGuiApplication). Hotkeys on console based applications are not supported (By the operating systems). You can however create a gui application without any visible window.
- C++11
### Known Limitations
- Only single key/modifier combinations are possible. If using QKeySequence, only the first key+modifier of the sequence will be used.
- Qt::Key makes no difference between normal numbers and the Numpad numbers. Most keyboards however require this. Thus, you can't register shortcuts for the numpad, unless you use a native shortcut.
- Supports not all keys, but most of the common ones. There are differences between platforms and it depends on the Keyboard-Layout. "Delete", for example, works on windows and mac, but not on X11 (At least on my test machines). I tried to use OS-Functions where possible, but since the Qt::Key values need to be converted into native keys, there are some limitations. I can use need such a key, try using the native shortcut.
- The registered keys will be "taken" by QHotkey. This means after a hotkey was cosumend by your application, it will not be sent to the active application. This is done this way by the operating systems and cannot be changed.
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
Qt5.15版本图片转文字识别程序源码,带完整类似QQ强大截图功能 MSVC2019或QT5.15下ReleaseX64编译,完整dll库全包含,可解析远程图片,本地图片 可自由截图识别或者打开电脑图片识别 程序代码方便修改,很适合毕业设计参考,工作项目应用,实际生活程序使用都可以。
资源推荐
资源详情
资源评论
收起资源包目录
Qt5.15版2022年4月最新版本图片转文字识别程序源码,带完整类似QQ强大截图功能 (585个子文件)
libQHotkey1.a 45KB
Makefile.am 1KB
BaiduOCR.aps 1KB
bitmap1.bmp 1KB
applink.c 4KB
moc_predefs.h.cbt 61B
moc_predefs.h.cbt 59B
moc_predefs.h.cbt 55B
moc_predefs.h.cbt 55B
qrc_res.cpp 195KB
qrc_res.cpp 134KB
qrc_style.cpp 79KB
qrc_style.cpp 79KB
capturewindow.cpp 35KB
settingswindow.cpp 15KB
toolwidget.cpp 11KB
moc_qhotkey.cpp 10KB
moc_qhotkey.cpp 10KB
moc_qhotkey.cpp 10KB
tmain.cpp 10KB
JsonParser.cpp 8KB
qhotkey.cpp 8KB
hottestwidget.cpp 8KB
core.cpp 7KB
qhotkey_mac.cpp 7KB
ocrmainwindow.cpp 7KB
moc_capturewindow.cpp 6KB
moc_capturewindow.cpp 6KB
qhotkey_win.cpp 6KB
moc_toolwidget.cpp 6KB
moc_toolwidget.cpp 6KB
moc_qhotkey_p.cpp 6KB
moc_qhotkey_p.cpp 6KB
moc_qhotkey_p.cpp 6KB
moc_customtextedit.cpp 5KB
moc_customtextedit.cpp 5KB
qhotkey_x11.cpp 5KB
moc_texttool.cpp 5KB
moc_texttool.cpp 5KB
moc_ocrmainwindow.cpp 5KB
moc_ocrmainwindow.cpp 5KB
texttool.cpp 5KB
moc_tmain.cpp 5KB
moc_tmain.cpp 5KB
moc_shapetool.cpp 4KB
moc_shapetool.cpp 4KB
moc_colorpanel.cpp 4KB
moc_colorpanel.cpp 4KB
moc_pentool.cpp 4KB
moc_pentool.cpp 4KB
moc_settingswindow.cpp 4KB
moc_settingswindow.cpp 4KB
shapetool.cpp 4KB
pentool.cpp 4KB
moc_colorpicker.cpp 4KB
moc_colorpicker.cpp 4KB
colorpanel.cpp 4KB
moc_arrowtool.cpp 4KB
moc_arrowtool.cpp 4KB
moc_inputtextedit.cpp 4KB
moc_inputtextedit.cpp 4KB
JsonConvert.cpp 3KB
pixelpanel.cpp 3KB
moc_pinwidget.cpp 3KB
moc_pinwidget.cpp 3KB
JsonObject.cpp 3KB
moc_imageuploader.cpp 3KB
moc_imageuploader.cpp 3KB
moc_core_fs_check.cpp 3KB
moc_core_fs_check.cpp 3KB
moc_basecombobox.cpp 3KB
moc_basecombobox.cpp 3KB
moc_pixelwidget.cpp 3KB
moc_pixelwidget.cpp 3KB
moc_basebutton.cpp 3KB
moc_basebutton.cpp 3KB
moc_pixelpanel.cpp 3KB
moc_pixelpanel.cpp 3KB
moc_erasetool.cpp 3KB
moc_erasetool.cpp 3KB
moc_separator.cpp 3KB
moc_separator.cpp 3KB
moc_basetool.cpp 3KB
moc_basetool.cpp 3KB
moc_drawer.cpp 3KB
moc_drawer.cpp 3KB
core_settings.cpp 2KB
erasetool.cpp 2KB
main.cpp 2KB
JsonArray.cpp 2KB
customtextedit.cpp 2KB
inputtextedit.cpp 2KB
basebutton.cpp 2KB
colorpicker.cpp 2KB
arrowdrawer.cpp 1KB
arrowtool.cpp 1KB
JsonDocument.cpp 1KB
pinwidget.cpp 1KB
imageblurdrawer.cpp 1KB
activewindow.cpp 1KB
共 585 条
- 1
- 2
- 3
- 4
- 5
- 6
资源评论
- 範小韦2023-03-03资源不错,内容挺好的,有一定的使用价值,值得借鉴,感谢分享。
- 云兮森严2023-05-02超赞的资源,感谢资源主分享,大家一起进步!
新潮技术研究社
- 粉丝: 1221
- 资源: 38
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功