holy SHIFT

This commit is contained in:
2025-12-28 11:06:33 +01:00
parent cc36c768cf
commit 4607b5aba5
4 changed files with 77 additions and 35 deletions

View File

@@ -4,6 +4,7 @@
#include "../io/printf.h"
#include "ps2.h"
#include <stdint.h>
#include "../io/term.h"
// The key status bitfield will be used to see if ALT, CONTROL, or SHIFT is pressed
uint8_t key_status = 0b00000000;
@@ -156,50 +157,55 @@ void keyboard_handler()
// Key release (bit 7 set)
if (scancode & 0x80)
{
if (key_status & SHIFT_PRESSED)
unsigned char code = scancode & 0x7F;
switch (code)
{
serial_kputs("SHIFT was released!\n");
key_status &= ~(1 << 0); // Unset SHIFT bit
// Clear the corresponding bit if corresponding key is released
case LEFT_SHIFT_PRESSED:
case RIGHT_SHIFT_PRESSED:
key_status &= ~SHIFT_PRESSED_BIT;
break;
case CTRL_PRESSED:
key_status &= ~CTRL_PRESSED_BIT;
break;
case ALT_PRESSED:
key_status &= ~ALT_PRESSED_BIT;
break;
}
if (key_status & ALT_PRESSED)
{
serial_kputs("ALT was released!\n");
key_status &= ~(1 << 1); // Unset ALT bit
}
if (key_status & CTRL_PRESSED)
{
serial_kputs("CTRL was released!\n");
key_status &= ~(1 << 2); // Unset CTRL bit
}
// Send EOI
outb(0x20, 0x20);
return;
}
else
{
// Key press
unsigned char character;
switch (keymap[scancode])
switch (scancode)
{
case SHIFT:
serial_kputs("SHIFT ");
key_status |= (1 << 0); // SHIFT bit
// Set bits for corresponding special key press
case LEFT_SHIFT_PRESSED:
case RIGHT_SHIFT_PRESSED:
key_status |= SHIFT_PRESSED_BIT;
break;
case ALT:
serial_kputs("ALT ");
key_status |= (1 << 1);
case CTRL_PRESSED:
key_status |= CTRL_PRESSED_BIT;
break;
case CTRL:
serial_kputs("CTRL ");
key_status |= (1 << 2);
case ALT_PRESSED:
key_status |= ALT_PRESSED_BIT;
break;
default:
character = (key_status & SHIFT_PRESSED) ? keymap_shifted[scancode] : keymap[scancode];
printf("%c", character);
break;
{
// Should we get a SHIFTED char or a regular one?
unsigned char c = (key_status & SHIFT_PRESSED_BIT) ? keymap_shifted[scancode] : keymap[scancode];
if (c)
{
putchar(c);
}
}
}
// Should we get a SHIFTED char or a regular one?
serial_kputs("key pressed!\n");
}