-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add g-key support for use in global shortcuts #1730
Closed
Closed
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
66e896d
Create gkey library proxy
forivall 39d2cd2
Gkeys working as shortcut keys
forivall 7efd302
Fix indentation
forivall 7ca7cb4
rename gkey files and classes
forivall 9d1ea1f
Add specification and usage for gkeys
forivall dab8857
Add "shorcuts/gkey" config optpion
forivall 23d9341
Use gkey uuids instead of different qlist format
forivall 9ed441e
Lookup dll location from registry
forivall 394545e
Update build settings: enable gkeys by default
forivall c96cf93
Address code issues in pr
forivall aab6f2a
Rename GKeys to GKey
forivall eea2710
Clean up single use variable
forivall fdefe2c
Use pure BSD license text
forivall File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
/* Copyright (C) 2015, Jordan J Klassen <forivall@gmail.com> | ||
|
||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions | ||
are met: | ||
|
||
- Redistributions of source code must retain the above copyright notice, | ||
this list of conditions and the following disclaimer. | ||
- Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
- Neither the name of the Mumble Developers nor the names of its | ||
contributors may be used to endorse or promote products derived from this | ||
software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR | ||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
/* SPECIFICATION | ||
* The code interfacing with the Logitech G-Keys DLL was implemented using the | ||
* following spec: | ||
* | ||
* The G-keys DLL lives in | ||
* "C:\Program Files\Logitech Gaming Software\SDK\G-key\x64\LogitechGkey.dll" for x64 and | ||
* "C:\Program Files\Logitech Gaming Software\SDK\G-key\x86\LogitechGkey.dll" for x86. | ||
* | ||
* Its location can also be read from the registry, using the following keys: | ||
* | ||
* x86: | ||
* "HKEY_CLASSES_ROOT\CLSID\{7bded654-f278-4977-a20f-6e72a0d07859}\ServerBinary" | ||
* | ||
* x64: | ||
* "HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{7bded654-f278-4977-a20f-6e72a0d07859}\ServerBinary" | ||
* | ||
* The registry keys are needed if a user installed the Logitech Gaming | ||
* Software in a non-standard location. | ||
* | ||
* The DLL has an init function, it's called "LogiGkeyInit". It takes a | ||
* pointer, but the parameter must always be NULL. The function returns a BOOL | ||
* as a status code. | ||
* | ||
* The DLL also has a shutdown function, called "LogiGkeyShutdown". It takes | ||
* no parameters and does not return anything. | ||
* | ||
* You can poll for button states with the DLL using the functions | ||
* "LogiGkeyIsMouseButtonPressed" and "LogiGkeyIsKeyboardGkeyPressed". | ||
* | ||
* The function "LogiGkeyIsMouseButtonPressed" takes a single int parameter, a | ||
* button number. Mouse button numbers run from 6 up to and including 20. The | ||
* function returns a BOOL that is true if the button is pressed, and false if | ||
* not. | ||
* | ||
* The function "LogiGkeyIsKeyboardGkeyPressed" takes two int parameters, a | ||
* button number and a mode number. Keyboard button numbers run from 1 up to | ||
* and including 29. The mode number can 1, 2 or 3. The mode checks the button | ||
* state in a specific mode. Typically, one queries all buttons for all modes, | ||
* so one ends up with 29*3 calls to the function. The function returns a BOOL | ||
* that is true if the button in the given mode is pressed, and false if not. | ||
* | ||
* There are also two functions, "LogiGkeyGetMouseButtonString" and | ||
* "LogiGkeyGetKeyboardGkeyString". They take the same parameters as the | ||
* polling functions above, but do not check whether the button is pressed or | ||
* not. Instead, they return the name of the button being queried as a pointer | ||
* to a NUL-terminated array of wchar_t's. Presumably, the pointer will be | ||
* NULL if the name cannot be retrieved or translated. | ||
*/ | ||
|
||
/* USAGE | ||
* In order to use the gkeys on a logitech keyboard, any user must have the | ||
* Logitech Gaming Software version 8.55+ installed on their computer. Then | ||
* (re)start mumble. When mumble initializes the library, the LGS (Logitech | ||
* Gaming Software) will create a profile called "mumble", featuring the mumble | ||
* icon. In LGS, right click this icon, and select either "Set as Default" or | ||
* "Set as Persistent". (See "What are persistent and default profiles?" in the | ||
* LGS help by clicking on the "?" icon on the LGS window, or at | ||
* http://www.logitech.com/assets/51813/3/lgs-guide.pdf). If mumble is not set | ||
* as the default or persistent profile, then your keys will not be active | ||
* unless mumble is the active window. | ||
*/ | ||
|
||
#include "mumble_pch.hpp" | ||
|
||
#include "GKey.h" | ||
|
||
#ifdef Q_CC_GNU | ||
#define RESOLVE(var) { var = reinterpret_cast<__typeof__(var)>(qlLogiGkey.resolve(#var)); bValid = bValid && (var != NULL); } | ||
#else | ||
#define RESOLVE(var) { * reinterpret_cast<void **>(&var) = static_cast<void *>(qlLogiGkey.resolve(#var)); bValid = bValid && (var != NULL); } | ||
#endif | ||
|
||
const QUuid GKeyLibrary::quMouse = QUuid(QString::fromLatin1(GKEY_MOUSE_GUID)); | ||
const QUuid GKeyLibrary::quKeyboard = QUuid(QString::fromLatin1(GKEY_KEYBOARD_GUID)); | ||
|
||
GKeyLibrary::GKeyLibrary() | ||
{ | ||
QStringList alternatives; | ||
|
||
HKEY key = NULL; | ||
DWORD type = 0; | ||
WCHAR wcLocation[510]; | ||
DWORD len = 510; | ||
if (RegOpenKeyEx(GKEY_LOGITECH_DLL_REG_HKEY, GKEY_LOGITECH_DLL_REG_PATH, NULL, KEY_READ, &key) == ERROR_SUCCESS) { | ||
LONG err = RegQueryValueEx(key, L"", NULL, &type, reinterpret_cast<LPBYTE>(wcLocation), &len); | ||
if (err == ERROR_SUCCESS && type == REG_SZ) { | ||
QString qsLocation = QString::fromUtf16(reinterpret_cast<ushort *>(wcLocation), len / 2); | ||
qWarning("GKeyLibrary: Found ServerBinary with libLocation = \"%s\", len = %d", qPrintable(qsLocation), len); | ||
alternatives << qsLocation; | ||
} else { | ||
qWarning("GKeyLibrary: Error looking up ServerBinary (Error: 0x%x, Type: 0x%x, len: %d)", err, type, len); | ||
} | ||
} | ||
|
||
alternatives << QString::fromLatin1(GKEY_LOGITECH_DLL_DEFAULT_LOCATION); | ||
foreach(const QString &lib, alternatives) { | ||
qlLogiGkey.setFileName(lib); | ||
|
||
if (qlLogiGkey.load()) { | ||
bValid = true; | ||
break; | ||
} | ||
} | ||
|
||
RESOLVE(LogiGkeyInit); | ||
RESOLVE(LogiGkeyShutdown); | ||
RESOLVE(LogiGkeyIsMouseButtonPressed); | ||
RESOLVE(LogiGkeyIsKeyboardGkeyPressed); | ||
RESOLVE(LogiGkeyGetMouseButtonString); | ||
RESOLVE(LogiGkeyGetKeyboardGkeyString); | ||
|
||
if (bValid) | ||
bValid = LogiGkeyInit(NULL); | ||
} | ||
|
||
GKeyLibrary::~GKeyLibrary() { | ||
if (LogiGkeyShutdown != NULL) | ||
LogiGkeyShutdown(); | ||
} | ||
|
||
bool GKeyLibrary::isValid() const { | ||
return bValid; | ||
} | ||
|
||
bool GKeyLibrary::isMouseButtonPressed(int button) { | ||
return LogiGkeyIsMouseButtonPressed(button); | ||
} | ||
|
||
bool GKeyLibrary::isKeyboardGkeyPressed(int key, int mode) { | ||
return LogiGkeyIsKeyboardGkeyPressed(key, mode); | ||
} | ||
|
||
QString GKeyLibrary::getMouseButtonString(int button) { | ||
return QString::fromWCharArray(LogiGkeyGetMouseButtonString(button)); | ||
} | ||
|
||
QString GKeyLibrary::getKeyboardGkeyString(int key, int mode) { | ||
return QString::fromWCharArray(LogiGkeyGetKeyboardGkeyString(key, mode)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* Copyright (C) 2015, Jordan J Klassen <forivall@gmail.com> | ||
|
||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions | ||
are met: | ||
|
||
- Redistributions of source code must retain the above copyright notice, | ||
this list of conditions and the following disclaimer. | ||
- Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
- Neither the name of the Mumble Developers nor the names of its | ||
contributors may be used to endorse or promote products derived from this | ||
software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR | ||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#ifndef MUMBLE_MUMBLE_GKEY_H | ||
#define MUMBLE_MUMBLE_GKEY_H | ||
|
||
#include <QtCore/QLibrary> | ||
#include <QtCore/QString> | ||
#include <QtCore/QUuid> | ||
|
||
#define GKEY_LOGITECH_DLL_REG_HKEY HKEY_CLASSES_ROOT | ||
#ifdef _M_X64 | ||
#define GKEY_LOGITECH_DLL_REG_PATH L"Wow6432Node\\CLSID\\{7bded654-f278-4977-a20f-6e72a0d07859}\\ServerBinary" | ||
#define GKEY_LOGITECH_DLL_DEFAULT_LOCATION "C:/Program Files/Logitech Gaming Software/SDK/G-key/x64/LogitechGkey.dll" | ||
#else | ||
#define GKEY_LOGITECH_DLL_REG_PATH L"CLSID\\{7bded654-f278-4977-a20f-6e72a0d07859}\\ServerBinary" | ||
#define GKEY_LOGITECH_DLL_DEFAULT_LOCATION "C:/Program Files/Logitech Gaming Software/SDK/G-key/x86/LogitechGkey.dll" | ||
#endif | ||
|
||
#define GKEY_MIN_MOUSE_BUTTON 6 | ||
#define GKEY_MAX_MOUSE_BUTTON 20 | ||
#define GKEY_MIN_KEYBOARD_BUTTON 1 | ||
#define GKEY_MAX_KEYBOARD_BUTTON 29 | ||
#define GKEY_MIN_KEYBOARD_MODE 1 | ||
#define GKEY_MAX_KEYBOARD_MODE 3 | ||
|
||
#define GKEY_BUTTON_MOUSE 1 | ||
#define GKEY_BUTTON_KEYBOARD 2 | ||
|
||
#define GKEY_MOUSE_GUID "c41e60af-9022-46cf-bc39-37981082d716" | ||
#define GKEY_KEYBOARD_GUID "153e64e6-98c8-4e03-80ef-5ffd33d25b8a" | ||
|
||
class GKeyLibrary | ||
{ | ||
public: | ||
GKeyLibrary(); | ||
virtual ~GKeyLibrary(); | ||
bool isValid() const; | ||
static const QUuid quMouse; | ||
static const QUuid quKeyboard; | ||
|
||
bool isMouseButtonPressed(int button); | ||
bool isKeyboardGkeyPressed(int key, int mode); | ||
QString getMouseButtonString(int button); | ||
QString getKeyboardGkeyString(int key, int mode); | ||
|
||
protected: | ||
QLibrary qlLogiGkey; | ||
bool bValid; | ||
|
||
BOOL (*LogiGkeyInit)(void *); | ||
void (*LogiGkeyShutdown)(); | ||
BOOL (*LogiGkeyIsMouseButtonPressed)(int button); | ||
BOOL (*LogiGkeyIsKeyboardGkeyPressed)(int key, int mode); | ||
wchar_t *(*LogiGkeyGetMouseButtonString)(int button); | ||
wchar_t *(*LogiGkeyGetKeyboardGkeyString)(int key, int mode); | ||
}; | ||
|
||
#endif // MUMBLE_MUMBLE_GKEY_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -151,6 +151,13 @@ void GlobalShortcutWin::run() { | |
hhMouse = SetWindowsHookEx(WH_MOUSE_LL, HookMouse, hSelf, 0); | ||
} | ||
|
||
#ifdef USE_GKEY | ||
if (g.s.bEnableGKey) { | ||
gkey = new GKeyLibrary(); | ||
qWarning("GlobalShortcutWin: GKeys initialized, isValid: %d", gkey->isValid()); | ||
} | ||
#endif | ||
|
||
QTimer * timer = new QTimer(this); | ||
connect(timer, SIGNAL(timeout()), this, SLOT(timeTicked())); | ||
timer->start(20); | ||
|
@@ -159,6 +166,10 @@ void GlobalShortcutWin::run() { | |
|
||
exec(); | ||
|
||
#ifdef USE_GKEY | ||
delete gkey; | ||
#endif | ||
|
||
if (bHook) { | ||
UnhookWindowsHookEx(hhKeyboard); | ||
UnhookWindowsHookEx(hhMouse); | ||
|
@@ -557,6 +568,26 @@ void GlobalShortcutWin::timeTicked() { | |
handleButton(ql, rgdod[j].dwData & 0x80); | ||
} | ||
} | ||
#ifdef USE_GKEY | ||
if (g.s.bEnableGKey && gkey->isValid()) { | ||
for (int button = GKEY_MIN_MOUSE_BUTTON; button <= GKEY_MAX_MOUSE_BUTTON; button++) { | ||
QList<QVariant> ql; | ||
ql << button; | ||
ql << GKeyLibrary::quMouse; | ||
handleButton(ql, gkey->isMouseButtonPressed(button)); | ||
} | ||
for (int mode = GKEY_MIN_KEYBOARD_MODE; mode <= GKEY_MAX_KEYBOARD_MODE; mode++) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indentation. |
||
for (int key = GKEY_MIN_KEYBOARD_BUTTON; key <= GKEY_MAX_KEYBOARD_BUTTON; key++) { | ||
QList<QVariant> ql; | ||
// Store the key and mode in one int | ||
// bit 0..15: mode, bit 16..31: key | ||
ql << (key | (mode << 16)); | ||
ql << GKeyLibrary::quKeyboard; | ||
handleButton(ql, gkey->isKeyboardGkeyPressed(key, mode)); | ||
} | ||
} | ||
} | ||
#endif | ||
} | ||
|
||
QString GlobalShortcutWin::buttonName(const QVariant &v) { | ||
|
@@ -575,6 +606,24 @@ QString GlobalShortcutWin::buttonName(const QVariant &v) { | |
|
||
QString device=guid.toString(); | ||
QString name=QLatin1String("Unknown"); | ||
|
||
#ifdef USE_GKEY | ||
if (g.s.bEnableGKey && gkey->isValid()) { | ||
bool isGKey = false; | ||
if (guid == GKeyLibrary::quMouse) { | ||
isGKey = true; | ||
name = gkey->getMouseButtonString(type); | ||
} else if (guid == GKeyLibrary::quKeyboard) { | ||
isGKey = true; | ||
name = gkey->getKeyboardGkeyString(type & 0xFFFF, type >> 16); | ||
} | ||
if (isGKey) { | ||
device = QLatin1String("GKey:"); | ||
return device + name; // Example output: "Gkey:G6/M1" | ||
} | ||
} | ||
#endif | ||
|
||
InputDevice *id = gsw->qhInputDevices.value(guid); | ||
if (guid == GUID_SysMouse) | ||
device=QLatin1String("M:"); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wierd, my editor switched to spaces for those lines. Fixed. Should I just squash in the indentation fix?