Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Capture and block keyboard and mouse events.
Forum Updated to NodeBB v4.3 + New Features

Capture and block keyboard and mouse events.

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 4.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Aditya1309
    wrote on last edited by Aditya1309
    #1

    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.

    raven-worxR 1 Reply Last reply
    0
    • A Aditya1309

      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.

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by raven-worx
      #2

      @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.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      3
      • A Offline
        A Offline
        Aditya1309
        wrote on last edited by
        #3

        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.

        raven-worxR 1 Reply Last reply
        1
        • A Aditya1309

          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.

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @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.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          A 1 Reply Last reply
          1
          • raven-worxR raven-worx

            @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.

            A Offline
            A Offline
            Aditya1309
            wrote on last edited by
            #5

            @raven-worx Thanks, I will try with low level platform dependent code to solve my problem.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              Aditya1309
              wrote on last edited by
              #6

              Marking as solved since trying a different approach. Thanks all. :)

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved