keyboard: add keycode functions to identify F1..F6 and 0..9

This commit is contained in:
Lephe 2020-07-16 17:29:12 +02:00
parent 5cac2cf7fc
commit e617ea63bf
Signed by untrusted user: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
2 changed files with 37 additions and 0 deletions

View File

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

23
src/keysc/keycodes.c Normal file
View File

@ -0,0 +1,23 @@
#include <gint/keyboard.h>
/* 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;
}