In a game I'm developing, I want to detect a NUMLOCK keypress (or keyup), like registering a "callback" function when it gets pressed.
I'm not asking to read its state in a given moment, I can do that already, nor I'm interested in changing its value. It's about being aware of the keypress when it happens so I don't have to poll its state every tenth of a sec or so.
The game uses curses, and currently a blocking getch(). Curses does not detect NUMLOCK keypresses, and I never expected it to (led-related keyboard don't "produce" any key), and I wonder if there is any way to do so that is better than than replacing the main curses loop with a non-blocking getch() and call a keyboard_leds() function to read current state.
For example: I could start a new thread after initializing curses, passing its stdscr screen as argument, and that thread would register register a callback function (say, special_keypress()) for the event of a NUMLOCK keypress. Thus, that function would only invoke keyboard_leds() when needed, and then update stdscr.
I'm not sure if this is possible, and I'm aware that I'll probably have to go down to some architecture-dependent stuff (kernel/X11, etc), so if a cross-platform solution is not possible, then I'm fine with a Linux-only one.