The lowest keyboard input level received by emacs lisp is the keyboard event , which combines basic code with the emacs modifier on / off settings ( meta , control , shift , hyper , super and alt ). Because of this combination, there seems to be no way for lisp code to find out when you, for example, press and hold the shift key. Also note that there is no representation on CAPS LOCK or NUM LOCK.
On the side, the emacs note does distinguish between newline and Cm , but at a very low level in lisp code, the former is mapped to the latter. See lisp/term/x-win.el (usually located under /usr/share/emacs/NN.X ) if you really want gory details.
So, from within emacs lisp, I find it impossible to do what you want.
However, you can embed text from external commands in the emacs mode line and update them regularly. Thus, in principle, you can find the linux command, which returns the status of lock, shift and numlock, as well as periodic injection into the command line. This probably doesn't suit your needs, as it will not update the model in real time when you press shift, caplock and numlock. But if you want to do this, check out the implementations of display-time-mode and display-battery-mode .
source share