1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
/*
* ========================================================================== *
* *
* This file is part of the Openterface Mini KVM App QT version *
* *
* Copyright (C) 2024 <info@openterface.com> *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation version 3. *
* *
* 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 General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
* ========================================================================== *
*/
#ifndef KEYBOARDMANAGER_H
#define KEYBOARDMANAGER_H
#include "../serial/SerialPortManager.h"
#include "ui/statusevents.h"
#include "KeyboardLayouts.h"
#include <QObject>
#include <QLoggingCategory>
#include <QSet>
#include <QMap>
#include <QLocale>
#include <QApplication>
#include <QInputMethod>
#include <QKeyEvent>
Q_DECLARE_LOGGING_CATEGORY(log_host_keyboard)
class KeyboardManager: public QObject
{
Q_OBJECT
public:
explicit KeyboardManager(QObject *parent = nullptr);
void handleKeyboardAction(int keyCode, int modifiers, bool isKeyDown);
/*
* Check if the key is a modifier key, eg: shift, ctrl, alt
*/
bool isModiferKeys(int keycode);
/*
* Check if the key is a keypad key
*/
bool isKeypadKeys(int keycode, int modifiers);
void pasteTextToTarget(const QString &text);
/*
* Send F1 to F12 functional keys
*/
void sendFunctionKey(int functionKeyCode);
/*
* Send ctrl + alt + del composite keys
*/
void sendCtrlAltDel();
void sendKey(int keyCode, int modifiers, bool isKeyDown);
void setKeyboardLayout(const QString& layoutName);
private:
QSet<unsigned int> currentMappedKeyCodes;
void handlePastingCharacters(const QString& text, const QMap<uint8_t, int>& charMapping);
bool needShiftWhenPaste(const QChar character);
int handleKeyModifiers(int modifierKeyCode, bool isKeyDown);
int currentModifiers = 0;
// Add this new method
void sendKeyToTarget(uint8_t keyCode, bool isPressed);
// Add these new constants
static const uint8_t CTRL_KEY = 0xE0;
static const uint8_t ALT_KEY = 0xE2;
static const uint8_t DEL_KEY = 0x4C;
QLocale m_locale;
void getKeyboardLayout();
unsigned int mappedKeyCode;
KeyboardLayoutConfig currentLayout;
// Define static members
static const QList<int> SHIFT_KEYS;
static const QList<int> CTRL_KEYS;
static const QList<int> ALT_KEYS;
static const QList<int> KEYPAD_KEYS;
static const QMap<int, uint8_t> functionKeyMap;
// Add these constants for key mappings
static const QMap<int, uint8_t> defaultKeyMap;
static const QMap<uint8_t, int> defaultCharMapping;
static const QList<char> defaultNeedShiftKeys;
QString mapModifierKeysToNames(int modifiers);
private slots:
};
#endif // KEYBOARDMANAGER_H
|