Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic global keyboard handling for windows with ALT+k #161
- Loading branch information
1 parent
705b373
commit 88bd51b
Showing
17 changed files
with
443 additions
and
5 deletions.
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
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
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,20 @@ | ||
/* | ||
* Copyright (C) 2019 Damir Porobic <https://github.com/damirporobic> | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
* Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
#include "AbstractKeyHandler.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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright (C) 2019 Damir Porobic <https://github.com/damirporobic> | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
* Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
#ifndef KSNIP_ABSTRACTKEYHANDLER_H | ||
#define KSNIP_ABSTRACTKEYHANDLER_H | ||
|
||
class AbstractKeyHandler | ||
{ | ||
public: | ||
AbstractKeyHandler() = default; | ||
virtual ~AbstractKeyHandler() = default; | ||
|
||
virtual bool registerKey() = 0; | ||
virtual bool isKeyPressed(void* message) = 0; | ||
}; | ||
|
||
#endif //KSNIP_ABSTRACTKEYHANDLER_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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright (C) 2019 Damir Porobic <https://github.com/damirporobic> | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
* Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
#include "DummyKeyHandler.h" | ||
|
||
bool DummyKeyHandler::registerKey() | ||
{ | ||
return false; | ||
} | ||
|
||
bool DummyKeyHandler::isKeyPressed(void* message) | ||
{ | ||
return false; | ||
} |
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,35 @@ | ||
/* | ||
* Copyright (C) 2019 Damir Porobic <https://github.com/damirporobic> | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
* Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
#ifndef KSNIP_DUMMYKEYHANDLER_H | ||
#define KSNIP_DUMMYKEYHANDLER_H | ||
|
||
#include "AbstractKeyHandler.h" | ||
|
||
class DummyKeyHandler : public AbstractKeyHandler | ||
{ | ||
public: | ||
DummyKeyHandler() = default; | ||
~DummyKeyHandler() override = default; | ||
|
||
bool registerKey() override; | ||
bool isKeyPressed(void* message) override; | ||
}; | ||
|
||
#endif //KSNIP_DUMMYKEYHANDLER_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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright (C) 2019 Damir Porobic <https://github.com/damirporobic> | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
* Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
#include "GlobalKeyboardShortcut.h" | ||
|
||
GlobalKeyboardShortcut::GlobalKeyboardShortcut(QApplication &app) : mKeyHandler(nullptr) | ||
{ | ||
mKeyHandler = KeyHandlerFactory::create(); | ||
|
||
mKeyHandler->registerKey(); | ||
|
||
auto keyEventFilter = new NativeKeyEventFilter(mKeyHandler); | ||
connect(keyEventFilter, &NativeKeyEventFilter::triggered, this, &GlobalKeyboardShortcut::pressed); | ||
app.installNativeEventFilter(keyEventFilter); | ||
} | ||
|
||
GlobalKeyboardShortcut::~GlobalKeyboardShortcut() | ||
{ | ||
delete mKeyHandler; | ||
} |
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,43 @@ | ||
/* | ||
* Copyright (C) 2019 Damir Porobic <https://github.com/damirporobic> | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
* Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
#ifndef KSNIP_GLOBALKEYBOARDSHORTCUT_H | ||
#define KSNIP_GLOBALKEYBOARDSHORTCUT_H | ||
|
||
#include <QApplication> | ||
#include <QObject> | ||
|
||
#include "NativeKeyEventFilter.h" | ||
#include "KeyHandlerFactory.h" | ||
|
||
class GlobalKeyboardShortcut : public QObject | ||
{ | ||
Q_OBJECT | ||
public: | ||
explicit GlobalKeyboardShortcut(QApplication &app); | ||
~GlobalKeyboardShortcut() override; | ||
|
||
signals: | ||
void pressed() const; | ||
|
||
private: | ||
AbstractKeyHandler *mKeyHandler; | ||
}; | ||
|
||
#endif //KSNIP_GLOBALKEYBOARDSHORTCUT_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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright (C) 2019 Damir Porobic <https://github.com/damirporobic> | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
* Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
#include "KeyHandlerFactory.h" | ||
|
||
AbstractKeyHandler* KeyHandlerFactory::create() | ||
{ | ||
#if defined(__APPLE__) | ||
return new DummyKeyHandler; | ||
#endif | ||
|
||
#if defined(__linux__) | ||
return new DummyKeyHandler; | ||
#endif | ||
|
||
#if defined(_WIN32) | ||
return new WinKeyHandler; | ||
#endif | ||
} |
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,41 @@ | ||
/* | ||
* Copyright (C) 2019 Damir Porobic <https://github.com/damirporobic> | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
* Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
#ifndef KSNIP_KEYHANDLERFACTORY_H | ||
#define KSNIP_KEYHANDLERFACTORY_H | ||
|
||
#if defined(__APPLE__) | ||
#include "DummyKeyHandler.h" | ||
#endif | ||
|
||
#if defined(__linux__) | ||
#include "DummyKeyHandler.h" | ||
#endif | ||
|
||
#if defined(_WIN32) | ||
#include "WinKeyHandler.h" | ||
#endif | ||
|
||
class KeyHandlerFactory | ||
{ | ||
public: | ||
static AbstractKeyHandler* create(); | ||
}; | ||
|
||
#endif //KSNIP_KEYHANDLERFACTORY_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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright (C) 2019 Damir Porobic <https://github.com/damirporobic> | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
* Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
#include "NativeKeyEventFilter.h" | ||
|
||
NativeKeyEventFilter::NativeKeyEventFilter(AbstractKeyHandler *keyHandler) | ||
{ | ||
mKeyHandler = keyHandler; | ||
} | ||
|
||
bool NativeKeyEventFilter::nativeEventFilter(const QByteArray&, void* message, long*) { | ||
|
||
if(mKeyHandler->isKeyPressed(message)) { | ||
emit triggered(); | ||
} | ||
return false; | ||
} |
Oops, something went wrong.