hi all!
i'll tell you how to determine the state of CapsLock (this code can be modifyed for NumLock/ScrollLock, but you are to do that by yourself)

note: this will work under windows and any system that uses X11.

the function is simple:

Qt Code:
  1. bool QMyClass::checkCapsLock()
  2. {
  3. // platform dependent method of determining if CAPS LOCK is on
  4. #ifdef Q_OS_WIN32 // MS Windows version
  5. return GetKeyState(VK_CAPITAL) == 1;
  6. #else // X11 version (Linux/Unix/Mac OS X/etc...)
  7. Display * d = XOpenDisplay((char*)0);
  8. bool caps_state = false;
  9. if (d)
  10. {
  11. unsigned n;
  12. XkbGetIndicatorState(d, XkbUseCoreKbd, &n);
  13. caps_state = (n & 0x01) == 1;
  14. }
  15. return caps_state;
  16. #endif
  17. }
To copy to clipboard, switch view to plain text mode 

but we must have some includes:

Qt Code:
  1. #ifdef Q_OS_WIN32
  2. # include <windows.h>
  3. #else
  4. # include <X11/XKBlib.h>
  5. #endif
To copy to clipboard, switch view to plain text mode 

to use X11/XKBLib.h, you have to install libx11-dev and link with -lX11

but there are some troubles!

for example, let's see eventFilter:

Qt Code:
  1. bool QMyClass::eventFilter(QObject* obj, QEvent* event)
  2. {
  3. if (event->type() == QEvent::KeyPress) {
  4. // ...
  5. }
  6. }
To copy to clipboard, switch view to plain text mode 

look's good, but won't work under X11:

Qt Code:
  1. error: expected token ':' got '2'
To copy to clipboard, switch view to plain text mode 

why? what happened?
everything is simple. just look at X11/X.h:

Qt Code:
  1. [186] #define KeyPress 2
To copy to clipboard, switch view to plain text mode 

so that's that! we need to #undef those defines that conflicts with QEvent::Type enum:

Qt Code:
  1. #ifdef Q_OS_WIN32
  2. # include <windows.h>
  3. #else
  4. # include <X11/XKBlib.h>
  5. # undef KeyPress
  6. # undef KeyRelease
  7. # undef FocusIn
  8. # undef FocusOut
  9. // etc...
  10. #endif
To copy to clipboard, switch view to plain text mode 

this will make some troubles if you want to use some specific X11 features, but i think if you are using Qt, you don't need that ;]

that's all, see ya =)

PS: sorry for my bad english