diff --git a/include/gint/keyboard.h b/include/gint/keyboard.h index 4bf8b3f..2777479 100644 --- a/include/gint/keyboard.h +++ b/include/gint/keyboard.h @@ -332,6 +332,12 @@ int keycode_function(int keycode); returns 7 for KEY_7) and -1 for other keys. */ int keycode_digit(int keycode); +/* keycode_alpha(): Identify keys A .. Z, space, double quotes + This function returns the ASCII character associated with keycodes when + ALPHA modifier is active. + Other keycodes, including "r" and "θ", return -1 (255). */ +uint8_t keycode_alpha(int keycode); + #ifdef __cplusplus } #endif diff --git a/src/keysc/keycodes.c b/src/keysc/keycodes.c index c178599..7849159 100644 --- a/src/keysc/keycodes.c +++ b/src/keysc/keycodes.c @@ -21,3 +21,28 @@ int keycode_digit(int keycode) return -1; } + +/* keycode_alpha(): Identify ASCII characters */ +uint8_t keycode_alpha(int keycode) +{ + const int Row = keycode >> 4; + const int Column = keycode & 0xf; + + switch (Row) + { + case 6: return 'A' + Column - 1; + case 5: return 'G' + Column - 1; + case 4: return 'M' + Column - 1; + case 3: return 'P' + Column - 1; + case 2: return 'U' + Column - 1; + case 1: + switch (Column) + { + case 1: return 'Z'; + case 2: return ' '; + case 3: return '\"'; + default: return -1; + } + default: return -1; + } +}