All Projects → Skycoder42 → Qhotkey

Skycoder42 / Qhotkey

Licence: bsd-3-clause
A global shortcut/hotkey for Desktop Qt-Applications

Projects that are alternatives of or similar to Qhotkey

Xpiks
Cross-Platform Image Keywording Software for microstock photographers and illustrators
Stars: ✭ 81 (-65.38%)
Mutual labels:  cross-platform, qt
Mne Cpp
MNE-CPP: A Framework for Electrophysiology
Stars: ✭ 104 (-55.56%)
Mutual labels:  cross-platform, qt
Otter Browser
Otter Browser aims to recreate the best aspects of the classic Opera (12.x) UI using Qt5
Stars: ✭ 1,289 (+450.85%)
Mutual labels:  cross-platform, qt
Extensionsindex
Slicer extensions index
Stars: ✭ 36 (-84.62%)
Mutual labels:  cross-platform, qt
Packer
Package and deploy apps built with NodeGui to all platforms
Stars: ✭ 137 (-41.45%)
Mutual labels:  cross-platform, qt
Nitroshare Desktop
Network file transfer application for Windows, OS X, & Linux
Stars: ✭ 1,150 (+391.45%)
Mutual labels:  cross-platform, qt
Nodegui Starter
A starter repo for NodeGui projects
Stars: ✭ 93 (-60.26%)
Mutual labels:  cross-platform, qt
Liteide
LiteIDE is a simple, open source, cross-platform Go IDE.
Stars: ✭ 6,657 (+2744.87%)
Mutual labels:  cross-platform, qt
Notepanda
📃 A simple cross-platform notepad. Based on Qt and C++.
Stars: ✭ 134 (-42.74%)
Mutual labels:  cross-platform, qt
Atomicdex Desktop
atomicDEX Desktop app - project codename "Dextop"
Stars: ✭ 126 (-46.15%)
Mutual labels:  cross-platform, qt
Qpmx
A frontend for qpm, to provide source and build caching
Stars: ✭ 13 (-94.44%)
Mutual labels:  cross-platform, qt
Swift
Swift XMPP client and Swiften XMPP library
Stars: ✭ 190 (-18.8%)
Mutual labels:  cross-platform, qt
Slicergitsvnarchive
Multi-platform, free open source software for visualization and image computing.
Stars: ✭ 896 (+282.91%)
Mutual labels:  cross-platform, qt
Arcgis Appstudio Samples
Collection of samples available in AppStudio for ArcGIS desktop to learn and help build your next app.
Stars: ✭ 78 (-66.67%)
Mutual labels:  cross-platform, qt
Nodegui
A library for building cross-platform native desktop applications with Node.js and CSS 🚀. React NodeGui : https://react.nodegui.org and Vue NodeGui: https://vue.nodegui.org
Stars: ✭ 7,324 (+3029.91%)
Mutual labels:  cross-platform, qt
Cutehmi
CuteHMI is an open-source HMI (Human Machine Interface) software written in C++ and QML, using Qt libraries as a framework. GitHub repository is a mirror!
Stars: ✭ 90 (-61.54%)
Mutual labels:  cross-platform, qt
Cutelyst
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
Stars: ✭ 671 (+186.75%)
Mutual labels:  cross-platform, qt
Flyingcarpet
Encrypted file transfer over ad hoc WiFi. No network infrastructure required, just two laptops in close range. Linux, Mac, and Windows.
Stars: ✭ 788 (+236.75%)
Mutual labels:  cross-platform, qt
Qhttpengine
HTTP server for Qt applications
Stars: ✭ 112 (-52.14%)
Mutual labels:  cross-platform, qt
Flameshot
Powerful yet simple to use screenshot software 🖥️ 📸
Stars: ✭ 15,429 (+6493.59%)
Mutual labels:  cross-platform, qt

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

Note: For now Wayland is not supported, as it is simply not possible to register a global shortcut with wayland. For more details, or possible Ideas on how to get Hotkeys working on wayland, see Issue #14.

Installation

The package is providet as qpm package, de.skycoder42.qhotkey. You can install it either via qpmx (preferred) or directly via qpm.

Via qpmx

qpmx is a frontend for qpm (and other tools) with additional features, and is the preferred way to install packages. To use it:

  1. Install qpmx (See GitHub - Installation)
  2. Install qpm (See GitHub - Installing, for windows see below)
  3. In your projects root directory, run qpmx install de.skycoder42.qhotkey

Via qpm

  1. Install qpm (See GitHub - 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 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:

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 Ctrl+Alt+Q (++Q on Mac). This will quit the application. The debug output will tell if the hotkey was successfully registered and that it was pressed.

#include <QHotkey>
#include <QApplication>
#include <QDebug>

int main(int argc, char *argv[])
{
	QApplication a(argc, argv);

	auto hotkey = new QHotkey(QKeySequence("ctrl+alt+Q"), true, &a);//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 "QHotkey". If you want to simply disable the logging, call the folling function somewhere in your code:

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.

The documentation was created using doxygen. It includes an HTML-documentation and Qt-Help files that can be included into QtCreator (QtAssistant) to show F1-Help (See Adding External Documentation for more details).

Technical

Requirements

  • Explicit support is only given down to the latest Qt LTS, 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.
  • If you get a QHotkey: Failed to register hotkey. Error: BadAccess (attempt to access private resource denied) error on X11, this means you are trying to register a hotkey that is private to X11. Those keys simply cannot be registered using the normal API
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].