keysc: add keycode_alpha to get ASCII of keycode

This commit is contained in:
陈湛明 2024-09-18 15:30:25 +00:00
parent ccdd4c227c
commit 3d03721118
2 changed files with 38 additions and 0 deletions

View file

@ -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

View file

@ -21,3 +21,35 @@ 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:
switch (Column)
{
case 1:
case 2:
case 3: return 'M' + Column - 1;
default: -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;
}
}