1*4882a593Smuzhiyun================= 2*4882a593SmuzhiyunKeyboard notifier 3*4882a593Smuzhiyun================= 4*4882a593Smuzhiyun 5*4882a593SmuzhiyunOne can use register_keyboard_notifier to get called back on keyboard 6*4882a593Smuzhiyunevents (see kbd_keycode() function for details). The passed structure is 7*4882a593Smuzhiyunkeyboard_notifier_param: 8*4882a593Smuzhiyun 9*4882a593Smuzhiyun- 'vc' always provide the VC for which the keyboard event applies; 10*4882a593Smuzhiyun- 'down' is 1 for a key press event, 0 for a key release; 11*4882a593Smuzhiyun- 'shift' is the current modifier state, mask bit indexes are KG_*; 12*4882a593Smuzhiyun- 'value' depends on the type of event. 13*4882a593Smuzhiyun 14*4882a593Smuzhiyun- KBD_KEYCODE events are always sent before other events, value is the keycode. 15*4882a593Smuzhiyun- KBD_UNBOUND_KEYCODE events are sent if the keycode is not bound to a keysym. 16*4882a593Smuzhiyun value is the keycode. 17*4882a593Smuzhiyun- KBD_UNICODE events are sent if the keycode -> keysym translation produced a 18*4882a593Smuzhiyun unicode character. value is the unicode value. 19*4882a593Smuzhiyun- KBD_KEYSYM events are sent if the keycode -> keysym translation produced a 20*4882a593Smuzhiyun non-unicode character. value is the keysym. 21*4882a593Smuzhiyun- KBD_POST_KEYSYM events are sent after the treatment of non-unicode keysyms. 22*4882a593Smuzhiyun That permits one to inspect the resulting LEDs for instance. 23*4882a593Smuzhiyun 24*4882a593SmuzhiyunFor each kind of event but the last, the callback may return NOTIFY_STOP in 25*4882a593Smuzhiyunorder to "eat" the event: the notify loop is stopped and the keyboard event is 26*4882a593Smuzhiyundropped. 27*4882a593Smuzhiyun 28*4882a593SmuzhiyunIn a rough C snippet, we have:: 29*4882a593Smuzhiyun 30*4882a593Smuzhiyun kbd_keycode(keycode) { 31*4882a593Smuzhiyun ... 32*4882a593Smuzhiyun params.value = keycode; 33*4882a593Smuzhiyun if (notifier_call_chain(KBD_KEYCODE,¶ms) == NOTIFY_STOP) 34*4882a593Smuzhiyun || !bound) { 35*4882a593Smuzhiyun notifier_call_chain(KBD_UNBOUND_KEYCODE,¶ms); 36*4882a593Smuzhiyun return; 37*4882a593Smuzhiyun } 38*4882a593Smuzhiyun 39*4882a593Smuzhiyun if (unicode) { 40*4882a593Smuzhiyun param.value = unicode; 41*4882a593Smuzhiyun if (notifier_call_chain(KBD_UNICODE,¶ms) == NOTIFY_STOP) 42*4882a593Smuzhiyun return; 43*4882a593Smuzhiyun emit unicode; 44*4882a593Smuzhiyun return; 45*4882a593Smuzhiyun } 46*4882a593Smuzhiyun 47*4882a593Smuzhiyun params.value = keysym; 48*4882a593Smuzhiyun if (notifier_call_chain(KBD_KEYSYM,¶ms) == NOTIFY_STOP) 49*4882a593Smuzhiyun return; 50*4882a593Smuzhiyun apply keysym; 51*4882a593Smuzhiyun notifier_call_chain(KBD_POST_KEYSYM,¶ms); 52*4882a593Smuzhiyun } 53*4882a593Smuzhiyun 54*4882a593Smuzhiyun.. note:: This notifier is usually called from interrupt context. 55