mirror of
https://github.com/Skycoder42/QHotkey.git
synced 2026-11-19 12:49:58 +03:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c9cfd8fb6f | ||
|
|
7d214ac41e | ||
|
|
83910c8eca |
+7
-1
@@ -279,7 +279,13 @@ bool QHotkeyPrivate::removeShortcutInvoked(QHotkey *hotkey)
|
|||||||
|
|
||||||
QHotkey::NativeShortcut QHotkeyPrivate::nativeShortcutInvoked(Qt::Key keycode, Qt::KeyboardModifiers modifiers)
|
QHotkey::NativeShortcut QHotkeyPrivate::nativeShortcutInvoked(Qt::Key keycode, Qt::KeyboardModifiers modifiers)
|
||||||
{
|
{
|
||||||
return {this->nativeKeycode(keycode), this->nativeModifiers(modifiers)};
|
bool ok1, ok2 = false;
|
||||||
|
auto k = nativeKeycode(keycode, ok1);
|
||||||
|
auto m = nativeModifiers(modifiers, ok2);
|
||||||
|
if(ok1 && ok2)
|
||||||
|
return {k, m};
|
||||||
|
else
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+16
-7
@@ -13,8 +13,8 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
// QHotkeyPrivate interface
|
// QHotkeyPrivate interface
|
||||||
quint32 nativeKeycode(Qt::Key keycode) Q_DECL_OVERRIDE;
|
quint32 nativeKeycode(Qt::Key keycode, bool &ok) Q_DECL_OVERRIDE;
|
||||||
quint32 nativeModifiers(Qt::KeyboardModifiers modifiers) Q_DECL_OVERRIDE;
|
quint32 nativeModifiers(Qt::KeyboardModifiers modifiers, bool &ok) Q_DECL_OVERRIDE;
|
||||||
bool registerShortcut(QHotkey::NativeShortcut shortcut) Q_DECL_OVERRIDE;
|
bool registerShortcut(QHotkey::NativeShortcut shortcut) Q_DECL_OVERRIDE;
|
||||||
bool unregisterShortcut(QHotkey::NativeShortcut shortcut) Q_DECL_OVERRIDE;
|
bool unregisterShortcut(QHotkey::NativeShortcut shortcut) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
@@ -35,9 +35,10 @@ bool QHotkeyPrivateMac::nativeEventFilter(const QByteArray &eventType, void *mes
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
quint32 QHotkeyPrivateMac::nativeKeycode(Qt::Key keycode)
|
quint32 QHotkeyPrivateMac::nativeKeycode(Qt::Key keycode, bool &ok)
|
||||||
{
|
{
|
||||||
// Constants found in NSEvent.h from AppKit.framework
|
// Constants found in NSEvent.h from AppKit.framework
|
||||||
|
ok = true;
|
||||||
switch (keycode) {
|
switch (keycode) {
|
||||||
case Qt::Key_Return:
|
case Qt::Key_Return:
|
||||||
return kVK_Return;
|
return kVK_Return;
|
||||||
@@ -120,7 +121,8 @@ quint32 QHotkeyPrivateMac::nativeKeycode(Qt::Key keycode)
|
|||||||
case Qt::Key_Up:
|
case Qt::Key_Up:
|
||||||
return kVK_UpArrow;
|
return kVK_UpArrow;
|
||||||
default:
|
default:
|
||||||
;
|
ok = false;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
UTF16Char ch = keycode;
|
UTF16Char ch = keycode;
|
||||||
@@ -157,11 +159,17 @@ quint32 QHotkeyPrivateMac::nativeKeycode(Qt::Key keycode)
|
|||||||
long idx = keyToChar[k] & kUCKeyOutputGetIndexMask;
|
long idx = keyToChar[k] & kUCKeyOutputGetIndexMask;
|
||||||
if (stateRec && idx < stateRec->keyStateRecordCount) {
|
if (stateRec && idx < stateRec->keyStateRecordCount) {
|
||||||
UCKeyStateRecord* rec = reinterpret_cast<UCKeyStateRecord*>(data + stateRec->keyStateRecordOffsets[idx]);
|
UCKeyStateRecord* rec = reinterpret_cast<UCKeyStateRecord*>(data + stateRec->keyStateRecordOffsets[idx]);
|
||||||
if (rec->stateZeroCharData == ch) return k;
|
if (rec->stateZeroCharData == ch) {
|
||||||
|
ok = true;
|
||||||
|
return k;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!(keyToChar[k] & kUCKeyOutputSequenceIndexMask) && keyToChar[k] < 0xFFFE) {
|
else if (!(keyToChar[k] & kUCKeyOutputSequenceIndexMask) && keyToChar[k] < 0xFFFE) {
|
||||||
if (keyToChar[k] == ch) return k;
|
if (keyToChar[k] == ch) {
|
||||||
|
ok = true;
|
||||||
|
return k;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -169,7 +177,7 @@ quint32 QHotkeyPrivateMac::nativeKeycode(Qt::Key keycode)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
quint32 QHotkeyPrivateMac::nativeModifiers(Qt::KeyboardModifiers modifiers)
|
quint32 QHotkeyPrivateMac::nativeModifiers(Qt::KeyboardModifiers modifiers, bool &ok)
|
||||||
{
|
{
|
||||||
quint32 nMods = 0;
|
quint32 nMods = 0;
|
||||||
if (modifiers & Qt::ShiftModifier)
|
if (modifiers & Qt::ShiftModifier)
|
||||||
@@ -182,6 +190,7 @@ quint32 QHotkeyPrivateMac::nativeModifiers(Qt::KeyboardModifiers modifiers)
|
|||||||
nMods |= controlKey;
|
nMods |= controlKey;
|
||||||
if (modifiers & Qt::KeypadModifier)
|
if (modifiers & Qt::KeypadModifier)
|
||||||
nMods |= kEventKeyModifierNumLockMask;
|
nMods |= kEventKeyModifierNumLockMask;
|
||||||
|
ok = true;
|
||||||
return nMods;
|
return nMods;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -25,8 +25,8 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
void activateShortcut(QHotkey::NativeShortcut shortcut);
|
void activateShortcut(QHotkey::NativeShortcut shortcut);
|
||||||
|
|
||||||
virtual quint32 nativeKeycode(Qt::Key keycode) = 0;//platform implement
|
virtual quint32 nativeKeycode(Qt::Key keycode, bool &ok) = 0;//platform implement
|
||||||
virtual quint32 nativeModifiers(Qt::KeyboardModifiers modifiers) = 0;//platform implement
|
virtual quint32 nativeModifiers(Qt::KeyboardModifiers modifiers, bool &ok) = 0;//platform implement
|
||||||
|
|
||||||
virtual bool registerShortcut(QHotkey::NativeShortcut shortcut) = 0;//platform implement
|
virtual bool registerShortcut(QHotkey::NativeShortcut shortcut) = 0;//platform implement
|
||||||
virtual bool unregisterShortcut(QHotkey::NativeShortcut shortcut) = 0;//platform implement
|
virtual bool unregisterShortcut(QHotkey::NativeShortcut shortcut) = 0;//platform implement
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
// QHotkeyPrivate interface
|
// QHotkeyPrivate interface
|
||||||
quint32 nativeKeycode(Qt::Key keycode) Q_DECL_OVERRIDE;
|
quint32 nativeKeycode(Qt::Key keycode, bool &ok) Q_DECL_OVERRIDE;
|
||||||
quint32 nativeModifiers(Qt::KeyboardModifiers modifiers) Q_DECL_OVERRIDE;
|
quint32 nativeModifiers(Qt::KeyboardModifiers modifiers, bool &ok) Q_DECL_OVERRIDE;
|
||||||
bool registerShortcut(QHotkey::NativeShortcut shortcut) Q_DECL_OVERRIDE;
|
bool registerShortcut(QHotkey::NativeShortcut shortcut) Q_DECL_OVERRIDE;
|
||||||
bool unregisterShortcut(QHotkey::NativeShortcut shortcut) Q_DECL_OVERRIDE;
|
bool unregisterShortcut(QHotkey::NativeShortcut shortcut) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
@@ -35,8 +35,9 @@ bool QHotkeyPrivateWin::nativeEventFilter(const QByteArray &eventType, void *mes
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
quint32 QHotkeyPrivateWin::nativeKeycode(Qt::Key keycode)
|
quint32 QHotkeyPrivateWin::nativeKeycode(Qt::Key keycode, bool &ok)
|
||||||
{
|
{
|
||||||
|
ok = true;
|
||||||
if(keycode <= 0xFFFF) {//Try to obtain the key from it's "character"
|
if(keycode <= 0xFFFF) {//Try to obtain the key from it's "character"
|
||||||
const SHORT vKey = VkKeyScanW(keycode);
|
const SHORT vKey = VkKeyScanW(keycode);
|
||||||
if(vKey > -1)
|
if(vKey > -1)
|
||||||
@@ -201,11 +202,12 @@ quint32 QHotkeyPrivateWin::nativeKeycode(Qt::Key keycode)
|
|||||||
return VK_OEM_FJ_TOUROKU;
|
return VK_OEM_FJ_TOUROKU;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
ok = false;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
quint32 QHotkeyPrivateWin::nativeModifiers(Qt::KeyboardModifiers modifiers)
|
quint32 QHotkeyPrivateWin::nativeModifiers(Qt::KeyboardModifiers modifiers, bool &ok)
|
||||||
{
|
{
|
||||||
quint32 nMods = 0;
|
quint32 nMods = 0;
|
||||||
if (modifiers & Qt::ShiftModifier)
|
if (modifiers & Qt::ShiftModifier)
|
||||||
@@ -216,6 +218,7 @@ quint32 QHotkeyPrivateWin::nativeModifiers(Qt::KeyboardModifiers modifiers)
|
|||||||
nMods |= MOD_ALT;
|
nMods |= MOD_ALT;
|
||||||
if (modifiers & Qt::MetaModifier)
|
if (modifiers & Qt::MetaModifier)
|
||||||
nMods |= MOD_WIN;
|
nMods |= MOD_WIN;
|
||||||
|
ok = true;
|
||||||
return nMods;
|
return nMods;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+11
-7
@@ -14,8 +14,8 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
// QHotkeyPrivate interface
|
// QHotkeyPrivate interface
|
||||||
quint32 nativeKeycode(Qt::Key keycode) Q_DECL_OVERRIDE;
|
quint32 nativeKeycode(Qt::Key keycode, bool &ok) Q_DECL_OVERRIDE;
|
||||||
quint32 nativeModifiers(Qt::KeyboardModifiers modifiers) Q_DECL_OVERRIDE;
|
quint32 nativeModifiers(Qt::KeyboardModifiers modifiers, bool &ok) Q_DECL_OVERRIDE;
|
||||||
bool registerShortcut(QHotkey::NativeShortcut shortcut) Q_DECL_OVERRIDE;
|
bool registerShortcut(QHotkey::NativeShortcut shortcut) Q_DECL_OVERRIDE;
|
||||||
bool unregisterShortcut(QHotkey::NativeShortcut shortcut) Q_DECL_OVERRIDE;
|
bool unregisterShortcut(QHotkey::NativeShortcut shortcut) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
@@ -58,7 +58,7 @@ bool QHotkeyPrivateX11::nativeEventFilter(const QByteArray &eventType, void *mes
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
quint32 QHotkeyPrivateX11::nativeKeycode(Qt::Key keycode)
|
quint32 QHotkeyPrivateX11::nativeKeycode(Qt::Key keycode, bool &ok)
|
||||||
{
|
{
|
||||||
KeySym keysym = XStringToKeysym(QKeySequence(keycode).toString(QKeySequence::NativeText).toLatin1().constData());
|
KeySym keysym = XStringToKeysym(QKeySequence(keycode).toString(QKeySequence::NativeText).toLatin1().constData());
|
||||||
if (keysym == NoSymbol) {
|
if (keysym == NoSymbol) {
|
||||||
@@ -70,13 +70,16 @@ quint32 QHotkeyPrivateX11::nativeKeycode(Qt::Key keycode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
Display *display = QX11Info::display();
|
Display *display = QX11Info::display();
|
||||||
if(display)
|
if(display) {
|
||||||
return XKeysymToKeycode(QX11Info::display(), keysym);
|
auto res = XKeysymToKeycode(QX11Info::display(), keysym);
|
||||||
else
|
if(res != 0)
|
||||||
|
ok = true;
|
||||||
|
return res;
|
||||||
|
} else
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
quint32 QHotkeyPrivateX11::nativeModifiers(Qt::KeyboardModifiers modifiers)
|
quint32 QHotkeyPrivateX11::nativeModifiers(Qt::KeyboardModifiers modifiers, bool &ok)
|
||||||
{
|
{
|
||||||
quint32 nMods = 0;
|
quint32 nMods = 0;
|
||||||
if (modifiers & Qt::ShiftModifier)
|
if (modifiers & Qt::ShiftModifier)
|
||||||
@@ -87,6 +90,7 @@ quint32 QHotkeyPrivateX11::nativeModifiers(Qt::KeyboardModifiers modifiers)
|
|||||||
nMods |= Mod1Mask;
|
nMods |= Mod1Mask;
|
||||||
if (modifiers & Qt::MetaModifier)
|
if (modifiers & Qt::MetaModifier)
|
||||||
nMods |= Mod4Mask;
|
nMods |= Mod4Mask;
|
||||||
|
ok = true;
|
||||||
return nMods;
|
return nMods;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
mac: LIBS += -framework Carbon
|
||||||
|
else:win32: LIBS += -luser32
|
||||||
|
else:unix {
|
||||||
|
QT += x11extras
|
||||||
|
LIBS += -lX11
|
||||||
|
}
|
||||||
+8
-12
@@ -1,20 +1,16 @@
|
|||||||
CONFIG += C++11
|
CONFIG += C++11
|
||||||
|
|
||||||
HEADERS += $$PWD/QHotkey/qhotkey.h \
|
PUBLIC_HEADERS += $$PWD/QHotkey/qhotkey.h
|
||||||
|
|
||||||
|
HEADERS += $$PUBLIC_HEADERS \
|
||||||
$$PWD/QHotkey/qhotkey_p.h
|
$$PWD/QHotkey/qhotkey_p.h
|
||||||
|
|
||||||
SOURCES += $$PWD/QHotkey/qhotkey.cpp
|
SOURCES += $$PWD/QHotkey/qhotkey.cpp
|
||||||
|
|
||||||
mac {
|
mac: SOURCES += $$PWD/QHotkey/qhotkey_mac.cpp
|
||||||
SOURCES += $$PWD/QHotkey/qhotkey_mac.cpp
|
else:win32: SOURCES += $$PWD/QHotkey/qhotkey_win.cpp
|
||||||
LIBS += -framework Carbon
|
else:unix: SOURCES += $$PWD/QHotkey/qhotkey_x11.cpp
|
||||||
} else:win32 {
|
|
||||||
SOURCES += $$PWD/QHotkey/qhotkey_win.cpp
|
|
||||||
LIBS += -luser32
|
|
||||||
} else:unix {
|
|
||||||
SOURCES += $$PWD/QHotkey/qhotkey_x11.cpp
|
|
||||||
QT += x11extras
|
|
||||||
LIBS += -lX11
|
|
||||||
}
|
|
||||||
|
|
||||||
INCLUDEPATH += $$PWD/QHotkey
|
INCLUDEPATH += $$PWD/QHotkey
|
||||||
|
|
||||||
|
include($$PWD/qhotkey.prc)
|
||||||
|
|||||||
@@ -1,22 +1,22 @@
|
|||||||
{
|
{
|
||||||
"name": "de.skycoder42.qhotkey",
|
|
||||||
"description": "A global shortcut/hotkey for Desktop Qt-Applications",
|
|
||||||
"author": {
|
"author": {
|
||||||
"name": "Skycoder",
|
"email": "skycoder42.de@gmx.de",
|
||||||
"email": "skycoder42.de@gmx.de"
|
"name": "Skycoder"
|
||||||
},
|
},
|
||||||
|
"dependencies": [
|
||||||
|
],
|
||||||
|
"description": "A global shortcut/hotkey for Desktop Qt-Applications",
|
||||||
|
"license": "BSD_3_CLAUSE",
|
||||||
|
"name": "de.skycoder42.qhotkey",
|
||||||
|
"pri_filename": "qhotkey.pri",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "GITHUB",
|
"type": "GITHUB",
|
||||||
"url": "https://github.com/Skycoder42/QHotkey.git"
|
"url": "https://github.com/Skycoder42/QHotkey.git"
|
||||||
},
|
},
|
||||||
"version": {
|
"version": {
|
||||||
"label": "1.1.4",
|
"fingerprint": "",
|
||||||
"revision": "",
|
"label": "1.2.1",
|
||||||
"fingerprint": ""
|
"revision": ""
|
||||||
},
|
},
|
||||||
"dependencies": [
|
|
||||||
],
|
|
||||||
"license": "BSD_3_CLAUSE",
|
|
||||||
"pri_filename": "qhotkey.pri",
|
|
||||||
"webpage": "https://github.com/Skycoder42/QHotkey"
|
"webpage": "https://github.com/Skycoder42/QHotkey"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
{
|
||||||
|
"dependencies": [
|
||||||
|
],
|
||||||
|
"license": {
|
||||||
|
"file": "LICENSE",
|
||||||
|
"name": "BSD_3_CLAUSE"
|
||||||
|
},
|
||||||
|
"prcFile": "qhotkey.prc",
|
||||||
|
"priFile": "qhotkey.pri",
|
||||||
|
"priIncludes": [
|
||||||
|
],
|
||||||
|
"publishers": {
|
||||||
|
"qpm": {
|
||||||
|
"author": {
|
||||||
|
"email": "skycoder42.de@gmx.de",
|
||||||
|
"name": "Skycoder"
|
||||||
|
},
|
||||||
|
"description": "A global shortcut/hotkey for Desktop Qt-Applications",
|
||||||
|
"name": "de.skycoder42.qhotkey",
|
||||||
|
"repository": {
|
||||||
|
"type": "GITHUB",
|
||||||
|
"url": "https://github.com/Skycoder42/QHotkey.git"
|
||||||
|
},
|
||||||
|
"webpage": "https://github.com/Skycoder42/QHotkey"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"source": false
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user