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
466
Reaction score
57
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.
 
Joined
Sep 4, 2022
Messages
131
Reaction score
16
hello ,

by "uint8_t" you get a values range from 0 to 255.

you should go trough 'ascii' table with a c lib, by custom code
you can make your code becoming 2 sided,
half for 'key strokes event' ,
and the next step about retrieving the good '\Display Character on screen\' using ASCII
 

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

No members online now.

Forum statistics

Threads
473,930
Messages
2,570,072
Members
46,522
Latest member
Mad-Ram

Latest Threads

Top