开发者

Block All Keyboard Input in a Linux Application (Using Qt or Mono)

开发者 https://www.devze.com 2022-12-22 06:37 出处:网络
I\'m working on a online quiz client where we use a dedicated custom-made linux distro which contains only the quiz client software along with text editors and other utility software. When the user ha

I'm working on a online quiz client where we use a dedicated custom-made linux distro which contains only the quiz client software along with text editors and other utility software. When the user has started the quiz, I want to prevent him/her from minimizing the window/closing it/switching to the desktop or other windows. The quizzes can be attempted using only the mouse, so I need the keyboard to be completed disabled for the period of the quiz. How could I do this, using Qt or Mono? I'm ready to开发者_如何学Python use any low-level libraries/drivers, if required.


You may use QWidget::grabKeyboard and QWidget::grabMouse, and please note the warning in comments:

Warning: Bugs in mouse-grabbing applications very often lock the terminal. Use this function with extreme caution, and consider using the -nograb command line option while debugging.


Have you looked at XGrabKeyboard? That should do a global grab of the keyboard.


Did you try to use EventFilter ? You have the opportunity to block all the events related to, as instance, keypress...

More information here : http://qt.nokia.com/doc/4.6/eventsandfilters.html

Hope it helps !

Something like :

bool MyWidget::event(QEvent *event)
{
    if (event->type() == QEvent::KeyPress) 
    {
        return true;
    }
    return QWidget::event(event);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号