From 747c381d7cf7f24b128ccaf27566b417d0e77573 Mon Sep 17 00:00:00 2001 From: Natasha Moongrave Date: Wed, 11 Mar 2026 11:20:49 +0100 Subject: rewrote keyboard_interrupt_handler() in src/interrupts.rs to use pc_keyboard package to translate scancodes into their proper keys and print them to the screen --- StrixKernel/src/interrupts.rs | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/StrixKernel/src/interrupts.rs b/StrixKernel/src/interrupts.rs index 6f19088..fbc6d67 100644 --- a/StrixKernel/src/interrupts.rs +++ b/StrixKernel/src/interrupts.rs @@ -87,28 +87,29 @@ extern "x86-interrupt" fn timer_interrupt_handler( extern "x86-interrupt" fn keyboard_interrupt_handler( _stack_frame: InterruptStackFrame) { - use x86_64::instructions::port::Port; - - let mut port = Port::new(0x60); - let scancode: u8 = unsafe { port.read() }; - - let key = match scancode { - 0x02 => Some('1'), - 0x03 => Some('2'), - 0x04 => Some('3'), - 0x05 => Some('4'), - 0x06 => Some('5'), - 0x07 => Some('6'), - 0x08 => Some('7'), - 0x09 => Some('8'), - 0x0a => Some('9'), - 0x0b => Some('0'), - _ => None, - }; - if let Some(key) = key { - print!("{}", key); - } + use pc_keyboard::{layouts, DecodedKey, HandleControl, Keyboard, ScancodeSet1}; + use spin::Mutex; + use x86_64::instructions::port::Port; + + lazy_static! { + static ref KEYBOARD: Mutex> = + Mutex::new(Keyboard::new(ScancodeSet1::new(), + layouts::Us104Key, HandleControl::Ignore) + ); + } + let mut keyboard = KEYBOARD.lock(); + let mut port = Port::new(0x60); + + let scancode: u8 = unsafe { port.read() }; + if let Ok(Some(key_event)) = keyboard.add_byte(scancode) { + if let Some(key) = keyboard.process_keyevent(key_event) { + match key { + DecodedKey::Unicode(character) => print!("{}", character), + DecodedKey::RawKey(key) => print!("{:?}", key), + } + } + } unsafe { PICS.lock() -- cgit v1.2.3