| Crates.io | polished_scancodes |
| lib.rs | polished_scancodes |
| version | 0.1.1 |
| created_at | 2025-06-12 08:25:03.891239+00 |
| updated_at | 2025-06-12 20:25:13.330696+00 |
| description | A library for handling and mapping keyboard scancodes in Rust. |
| homepage | |
| repository | https://codeberg.org/ofluffydev/polished |
| max_upload_size | |
| id | 1709531 |
| size | 13,377 |
scancodes)This crate provides utilities for handling keyboard scancodes in x86 OS development. It is designed for use in kernels or low-level system software that needs to interpret raw keyboard input from hardware interrupts.
When a key is pressed or released on a PC keyboard, the hardware sends a scancode to the system via the PS/2 controller. These scancodes are received by the OS through keyboard interrupts (typically IRQ1). The scancodes library provides:
#![no_std] environments (OS kernels, bootloaders).If using as part of a workspace:
[dependencies]
scancodes = { path = "../scancodes" }
// In your keyboard interrupt handler (IRQ1):
use scancodes::{decode_scancode, KeyEvent};
fn keyboard_interrupt_handler() {
let scancode = unsafe { inb(0x60) }; // Read from PS/2 data port
if let Some(event) = decode_scancode(scancode) {
match event {
KeyEvent::Pressed(key) => { /* handle key press */ },
KeyEvent::Released(key) => { /* handle key release */ },
}
}
}
decode_scancode is a typical function provided to convert a raw scancode into a high-level event.If you want to convert key events to ASCII (for text input):
if let Some(ascii) = scancodes::key_to_ascii(key, shift_active) {
// Use ASCII character (e.g., print to screen or buffer)
}
This crate is licensed under the zlib License. See the root LICENSE file for details.
For questions or contributions, see the main Polished OS repository.