Skip to content

Commit

Permalink
Client: modify eventfilter for Key_meta
Browse files Browse the repository at this point in the history
  • Loading branch information
KangLin committed May 20, 2023
1 parent 8679a19 commit e48585e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 15 deletions.
23 changes: 18 additions & 5 deletions Client/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ CClient::CClient(QObject *parent) : QObject(parent),
check = connect(&m_ParameterClient, SIGNAL(sigHookKeyboardChanged()),
this, SLOT(slotHookKeyboardChanged()));
Q_ASSERT(check);
// TODO: Disabe it ?
if(m_ParameterClient.GetHookKeyboard())
m_Hook = QSharedPointer<CHook>(CHook::GetHook());
}
Expand Down Expand Up @@ -258,7 +259,8 @@ void CClient::slotHookKeyboardChanged()
{
m_Hook = QSharedPointer<CHook>(CHook::GetHook());
} else {
m_Hook.reset();
if(m_Hook)
m_Hook.reset();
}
}

Expand All @@ -269,7 +271,17 @@ bool CClient::eventFilter(QObject *watched, QEvent *event)
//qDebug(Client) << "eventFilter:" << event;
bool bProcess = false;
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
switch (keyEvent->key()) {
int key = keyEvent->key();
switch (key) {
case Qt::Key_Meta:
#if defined(Q_OS_WIN)
key = Qt::Key_Super_L;
#endif
#if defined(Q_OS_MACOS)
key = Qt::Qt::Key_Control;
#endif
bProcess = true;
break;
case Qt::Key_Tab:
case Qt::Key_Alt:
bProcess = true;
Expand All @@ -284,19 +296,20 @@ bool CClient::eventFilter(QObject *watched, QEvent *event)
{
CFrmViewer* focus = qobject_cast<CFrmViewer*>(QApplication::focusWidget());
if(focus) {
emit focus->sigKeyPressEvent(keyEvent->key(), keyEvent->modifiers());
emit focus->sigKeyPressEvent(key, keyEvent->modifiers());
return true;
}
}
case QEvent::KeyRelease:
{
CFrmViewer* focus = qobject_cast<CFrmViewer*>(QApplication::focusWidget());
if(focus) {
emit focus->sigKeyReleaseEvent(keyEvent->key(), keyEvent->modifiers());
emit focus->sigKeyReleaseEvent(key, keyEvent->modifiers());
return true;
}

}
default:
break;
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions Client/FrmViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,16 +190,16 @@ void CFrmViewer::wheelEvent(QWheelEvent *event)

void CFrmViewer::keyPressEvent(QKeyEvent *event)
{
//qDebug(Client) << "keyPressEvent key:" << event->key() << "modifiers:" << event->modifiers();
//qDebug(Client) << "CFrmViewer::keyPressEvent" << event;
emit sigKeyPressEvent(event->key(), event->modifiers());
//event->accept();
event->accept();
}

void CFrmViewer::keyReleaseEvent(QKeyEvent *event)
{
//qDebug(Client) << "keyReleaseEvent key:" << event->key() << "modifiers:" << event->modifiers();
//qDebug(Client) << "CFrmViewer::keyReleaseEvent" << event;
emit sigKeyReleaseEvent(event->key(), event->modifiers());
//event->accept();
event->accept();
}

void CFrmViewer::slotSystemCombination()
Expand Down
21 changes: 15 additions & 6 deletions Client/Windows/HookWindows.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#include "HookWindows.h"
#include "FrmViewer.h"
#include <QApplication>
#include <QDebug>

#include <QLoggingCategory>

Q_LOGGING_CATEGORY(clientHookWindows, "Client.Hook.Windows")

CHook* CHook::GetHook(QObject *parent)
{
Expand All @@ -20,7 +23,7 @@ CHookWindows::CHookWindows(QObject *parent)

CHookWindows::~CHookWindows()
{
qDebug() << "CHookWindows::~CHookWindows()";
qDebug(clientHookWindows) << "CHookWindows::~CHookWindows()";
UnRegisterKeyboard();
}

Expand All @@ -30,8 +33,10 @@ LRESULT CALLBACK CHookWindows::keyboardHookProc(INT code, WPARAM wparam, LPARAM
if (code == HC_ACTION)
{
KBDLLHOOKSTRUCT* hook = reinterpret_cast<KBDLLHOOKSTRUCT*>(lparam);
// LOG_MODEL_DEBUG("CHookWindows", "vkCode: 0x%X; scanCode: 0x%X; flags: 0x%X",
// hook->vkCode, hook->scanCode, hook->flags);
/*
qDebug(clientHookWindows) << "process vkCode:" << hook->vkCode
<< "scanCode:" << hook->scanCode
<< "flags:" << hook->flags;//*/
int key = 0;
Qt::KeyboardModifiers keyMdf = Qt::NoModifier;
switch(hook->vkCode)
Expand All @@ -49,11 +54,13 @@ LRESULT CALLBACK CHookWindows::keyboardHookProc(INT code, WPARAM wparam, LPARAM
case VK_LWIN:
{
key = Qt::Key_Super_L;
keyMdf = Qt::MetaModifier;
break;
}
case VK_RWIN:
{
key = Qt::Key_Super_R;
keyMdf = Qt::MetaModifier;
break;
}
/*
Expand Down Expand Up @@ -93,8 +100,10 @@ LRESULT CALLBACK CHookWindows::keyboardHookProc(INT code, WPARAM wparam, LPARAM
emit self->sigKeyPressEvent(key, keyMdf);
if(wparam == WM_KEYUP || wparam == WM_SYSKEYUP)
emit self->sigKeyReleaseEvent(key, Qt::NoModifier);
// LOG_MODEL_DEBUG("CHookWindows", "process vkCode: 0x%X; scanCode: 0x%X; flags: 0x%X",
// hook->vkCode, hook->scanCode, hook->flags);
/*
qDebug(clientHookWindows) << "process vkCode:" << hook->vkCode
<< "scanCode:" << hook->scanCode
<< "flags:" << hook->flags;//*/
return 0;
}
}
Expand Down

0 comments on commit e48585e

Please sign in to comment.