diff --git a/include/gint/keyboard.h b/include/gint/keyboard.h index 48aaef6..8225954 100644 --- a/include/gint/keyboard.h +++ b/include/gint/keyboard.h @@ -244,4 +244,18 @@ key_event_t getkey_opt(int options, volatile int *timeout); @next Delay between subsequent repeats (no more than one hour) */ void getkey_repeat(int first, int next); +//--- +// Key code functions +//--- + +/* keycode_function(): Identify keys F1 .. F6 + This function returns number of each F-key (eg. it returns 2 for KEY_F2), + and -1 for other keys. */ +int keycode_function(int keycode); + +/* keycode_digit(): Identify keys 0 .. 9 + This function returns the digit associated with digit keycodes (eg. it + returns 7 for KEY_7) and -1 for other keys. */ +int keycode_digit(int keycode); + #endif /* GINT_KEYBOARD */ diff --git a/src/keysc/keycodes.c b/src/keysc/keycodes.c new file mode 100644 index 0000000..c178599 --- /dev/null +++ b/src/keysc/keycodes.c @@ -0,0 +1,23 @@ +#include + +/* keycode_function(): Identify keys F1 .. F6 */ +int keycode_function(int keycode) +{ + if((keycode & 0xf0) != 0x90) return -1; + return keycode & 0x0f; +} + +/* keycode_digit(): Identify keys 0 .. 9 */ +int keycode_digit(int keycode) +{ + int row = keycode >> 4; + int col = keycode & 0xf; + + if(col > 3) return -1; + if(keycode == 0x11) return 0; + + int digit = 3 * row + col - 6; + if(digit >= 1 && digit <= 9) return digit; + + return -1; +}