You can do it in Java. Windows, Linux and MacOS all support Java. It's a one liner:
boolean zCapsLockOn = java.awt.Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
To do the same thing in binary code would require you (A) assume its an x86 machine, and (B) detect the operating system, which would be complex. If you did this, though, you could then make the OS-specific calls to get the capslock state based on which OS it was.
You can potentially do this platform check with Qt using code like this:
bool QMyClass::checkCapsLock()
{
// platform dependent method of determining if CAPS LOCK is on
#ifdef Q_OS_WIN32 // MS Windows version
return GetKeyState(VK_CAPITAL) == 1;
#else // X11 version (Linux/Unix/Mac OS X/etc...)
Display * d = XOpenDisplay((char*)0);
bool caps_state = false;
if (d)
{
unsigned n;
XkbGetIndicatorState(d, XkbUseCoreKbd, &n);
caps_state = (n & 0x01) == 1;
}
return caps_state;
#endif
}
Note that you cannot write binary code to get the CAPSLOCK state directly from the BIOS without going through the operating system, which is why any such code is OS-dependent.