[英]Block All Keyboard Input in a Linux Application (Using Qt or Mono)
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. 我正在使用一个在线测验客户端,我们在其中使用专用的定制linux发行版,该发行版仅包含测验客户端软件以及文本编辑器和其他实用程序软件。 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?
如何使用Qt或Mono做到这一点? I'm ready to use any low-level libraries/drivers, if required.
如果需要,我准备使用任何低级库/驱动程序。
You may use QWidget::grabKeyboard and QWidget::grabMouse, and please note the warning in comments: 您可以使用QWidget :: grabKeyboard和QWidget :: grabMouse,请注意注释中的警告:
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.
谨慎使用此功能,并在调试时考虑使用-nograb命令行选项。
Did you try to use EventFilter ? 您是否尝试使用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 此处的更多信息: 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);
}
Have you looked at XGrabKeyboard ? 您看过XGrabKeyboard吗? That should do a global grab of the keyboard.
那应该在全球范围内抢占键盘。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.