PDA

View Full Version : Capslock status



deepal_de
15th August 2011, 09:44
How can i get the status of capslock?
is there any function in Qt to get this??

cplus
15th August 2011, 09:56
bool 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
}

dswartz
6th September 2011, 19:43
Am I correct in assuming that if

caps_state = (n & 0x01) == 1;

will give me the state of the caps lock, that to find num, scroll, and kana lock i need to just do:

num_state = (n & 0x02) == 2;
scroll_state = (n & 0x04) == 4;
kana_state = (n & 0x08) == 8;

Is this correct? I have verified that this will work for number lock and that it *should* work for scroll lock, but i have no clue about kana lock. I have the bitwise masks for them being

caps_lock = $ffe5
num_lock = $ff7f
scroll_lock = $ff14
kana_lock = $ff2d

but i dont see how this is helpful in determining their current states. Is there somewhere that I can find the appropriate masks for these as it pertains to XkbGetIndicatorState???