Hi, 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 use any low-level libraries/drivers, if required. Thanks Evans
+1
A:
Hey,
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);
}
Andy M
2010-03-10 12:34:03
Can I use this to block "global" key presses like alt+tab, control+alt+del? I don't think so.
Evans
2010-03-10 12:51:03
Edit : I tried and you're right, It's not working with multiple key presses... I don't get why... There should be something you can do to "walk around" that problem... You could also have a look at examples of KeyLoggers...
Andy M
2010-03-10 13:49:19
+4
A:
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.
Mason Chang
2010-03-10 13:56:51
It is very annoying when an application that has a grab hangs or becomes unresponsive for longer periods of time, so use with care. If you ever get into this kind of situation, your only rescue is to press sysrq+alt+r (to switch to basic kernel keyboard handler) and then alt+f1 (to switch to text console), then kill your app. You need to turn on "magic sysrq" key by ` echo 1 > /proc/sys/kernel/sysrq`.
liori
2010-03-10 14:11:19
So, I can use QWidget::grabKeyboard to totally block all keyboard input, even special ones like Alt+Tab, Control+Alt+F1, Control+Alt+Del etc? Plus, will it work in GNOME? Is it possible to call this function directly from Mono?
Evans
2010-03-11 03:52:37
I didn't try this one GNONE nor Mono. Could you have a try? and please be sure to add an "EXIT" button on your testing widget.
Mason Chang
2010-03-11 04:49:01
Hi, I created a simple Qt Application to test this. I used window.grabKeyboard(). There was not effect - I tested it on GNOME as well as in KDE. Any suggestions? Any sequence of calls I must use to get it to work?
Evans
2010-03-12 04:37:55
A:
Have you looked at XGrabKeyboard? That should do a global grab of the keyboard.
Chris
2010-03-11 17:21:14