EventFilter show events returned
-
Hi i put the class eventfilter but how i can show in the main of my program the events of this filter. Class:
class FiltroDeEventosPersonalizado : public QObject { Q_OBJECT protected: bool eventFilter(QObject *obj, QEvent *event) override; }; Method : bool FiltroDeEventosPersonalizado::eventFilter( QObject *obj, QEvent *event) { if (event->type() == QEvent::KeyPress) { QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event); if( keyEvent->key() == Qt::Key_A ) qDebug() << "Tecla 'A' presionada"; return true; } return QObject::eventFilter(obj, event); } Main of my program: #include <QCoreApplication> #include <filtrodeeventospersonalizado.h> #include <QDebug> // main of my program ! -xd int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); //i want show the events with Qdebug return a.exec(); }
Edit: Added code tags -- @Wieland
-
Hi
Im not 100% sure what you hope to catch as your code seems to lack a mainwindow?http://doc.qt.io/qt-5/qobject.html#installEventFilter
so
maybe
a.installEventFilter( new FiltroDeEventosPersonalizado() ); -
Hi! This posting of mine shows an example use of an application global event filter: https://forum.qt.io/topic/71813/qwidget-objects-with-qt-window-flag-set-do-not-pass-on-ignored-events/3
BTW: Please use markup for source code inside your postings (three backticks). Also, once your problem is solved, please mark it as solved instead of deleting it (see Hitchhiker's Visual Guide to the Qt Forum).
-
Hi! This posting of mine shows an example use of an application global event filter: https://forum.qt.io/topic/71813/qwidget-objects-with-qt-window-flag-set-do-not-pass-on-ignored-events/3
BTW: Please use markup for source code inside your postings (three backticks). Also, once your problem is solved, please mark it as solved instead of deleting it (see Hitchhiker's Visual Guide to the Qt Forum).
@Wieland One question about this with eventfilter i can capture the events and filter them. But if for example i want to create one application to save all events pressed in my computer. It's necessary to use a Hook. Thx a lot for your answer and i vote sorry i forgot.
-
@Wieland One question about this with eventfilter i can capture the events and filter them. But if for example i want to create one application to save all events pressed in my computer. It's necessary to use a Hook. Thx a lot for your answer and i vote sorry i forgot.
@RIVOPICO You mean like in spyware?
-
Or automation software :)
https://msdn.microsoft.com/en-us/library/windows/desktop/ms644990(v=vs.85).aspx -
@RIVOPICO You mean like in spyware?
-
@Wieland And so if i am using Mac i coudnt save my keystrokes. ? In linux for example i can.
thx. Specify i could see some programs in linux and windows since store to register your activity nothing more.@RIVOPICO I don't understand what you mean. What I meant to say was that you need to use the Windows API to capture all keyboard input on the machine. I don't know how this works on Linux. I guess you can get the key strokes from the X server (with proper access rights), or maybe from the window manager. Or maybe from the input's device file, IDK. Also I have no idea how it would be done on macOS.