Is there a better way of doing this?

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:

image_2024-09-18_125509259.png
 
Joined
Jul 4, 2023
Messages
455
Reaction score
54
Have you tried something like this, e.g. array?

C:
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
}

I apologize if this code is not entirely compatible with the C language, but C is not the language I use.
 

Ask a Question

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.

Ask a Question

Members online

Forum statistics

Threads
473,882
Messages
2,569,950
Members
46,278
Latest member
Sherman196

Latest Threads

Top