Reputation: 11
I am programming an operating system and I want to handle the instruction. The code prints to the screen the letters pressed but I don't know how to check if the CapsLock key is pressed. I assume there is a port that contains its state. I have a function that can return the value of a port:
uint8_t port_byte_in (uint16_t port) {
uint8_t result;
asm("in %%dx, %%al" : "=a" (result) : "d" (port));// Inline assembler syntax
return result;}
I someone can help me find the needed port or have another idea of how to check if the CapsLock key is pressed that would be great : )
Upvotes: 0
Views: 885
Reputation: 18503
I assume there is a port that contains its state.
No:
For the hardware, the Caps Lock key is just a key like other keys (e.g. "A").
However, the software (e.g. the BIOS) reacts on the Caps Lock key differently:
Whenever you press the key, it changes the value of a "variable" from true to false or vice versa. Then it sends a command to the keyboard that the LED shall be switched on or off.
Your system will have to do this!
Communication with the keyboard (both reading the keys and setting the LEDs) is done using ports. However, it is much more complicated than you think.
You may have a look at the information about the keyboard itself and about the keyboard controller on the OSDev website.
The BIOS stores the information if Caps Lock is active in bit 6 of the byte at address 40:18 (hex).
You can use this information when your system starts up.
Upvotes: 2