Solved Capture and block keyboard and mouse events.
-
Hi,
I want to create a transparent fullscreen widget and block all keyboard press(including special key ctrl+alt ) and mouse events before it goes to system level. The widget should be enabled for 30 seconds along with timer.
eg: When widget opens user tries to press keys it should be non-responsive along with special keys as well as mouse for 30 Secs. After that the widget should disappear.*It should work in both windows and linux.
-
@Aditya1309
not all keys can be captured. Since the system always receives/creates the event first and then forwards them to the window with input focus.But you may want to have a look at QWidget::grabMouse() / QWidget::grabKeyboard() and accept all events it receives.
-
Hi,
I have created a sample application.#include "mywidget.h"
#include "ui_mywidget.h"MyWidget::MyWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::MyWidget)
{
ui->setupUi(this);
QObject::connect(this, SIGNAL(mysignal()), this, SLOT(specialKeyPressed()));
this->installEventFilter(this);
this->grabKeyboard();
setFocusPolicy(Qt::ClickFocus);
}MyWidget::~MyWidget()
{
delete ui;
this->releaseKeyboard();
}bool MyWidget::eventFilter(QObject *obj, QEvent *event)
{if(obj == this) { QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event); if ( keyEvent->type() == QEvent::KeyPress) { emit mysignal(); } } return true;
}
void MyWidget::specialKeyPressed()
{
qDebug()<<"In slot specialkeypressed";}
In the above case I am able to grab key press event but when I press windows key. It gets transferred to windows explorer too.
I want to block windows key event and prevent the start menu from popping-up.
Let me know what additional I have to do. -
@Aditya1309 said in Capture and block keyboard and mouse events.:
Let me know what additional I have to do.
can't tell you exactly, but this is clearly out of the scope of Qt (for the reasons i mentioned)
Maybe there is a native API you can use, but i guess Windows has the Windows Key reserved for it's own purpose. -
@raven-worx Thanks, I will try with low level platform dependent code to solve my problem.
-
Marking as solved since trying a different approach. Thanks all. :)