- Joined
- Sep 18, 2024
- Messages
- 1
- Reaction score
- 0
So, I've been coding a kernel for my OS in C, and I recently came across keyboard support. I was using scancodes, and I'm wondering, is there a better way to do this:
char lowercase[] = "abcdefghijklmnopqrstuvwxyz";
char uppercase[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char scancode_to_char(uint8_t scancode, bool shift, bool caps_lock) {
bool upper = shift ^ caps_lock;
if (scancode >= KEY_A && scancode <= KEY_Z) {
return upper ? uppercase[scancode - KEY_A] : lowercase[scancode - KEY_A];
} else if (scancode == KEY_SPACE) {
return ' ';
}
// Handle other keys, such as numbers and punctuation
return '\0'; // Unknown key
}
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.