Skip to main content

Crate polished_scancodes

Crate polished_scancodes 

Source
Expand description

PS/2 Keyboard Scancode to Keysym/ASCII Mapping Library

This module provides translation from PS/2 Set 1 keyboard scancodes (as generated by the keyboard controller and delivered via PS/2/IRQ1) to symbolic key representations (Keysym) and ASCII values. It is designed for use in low-level OS code where keyboard input is handled via hardware interrupts and raw scancodes are received from the PS/2 controller.

§How Scancodes Work

When a key is pressed or released on a PS/2 keyboard, the controller sends a scancode byte to port 0x60, which is typically read in the keyboard interrupt handler (IRQ1). The scancode identifies which key was pressed or released, but does not directly correspond to ASCII.

This module uses the standard PS/2 Set 1 scancode set (used by most PC keyboards in legacy mode). Each scancode is mapped to a u16 value:

  • For printable keys, this is the ASCII code (e.g., ‘A’ as u16).
  • For special keys (Ctrl, Shift, Fn, etc.), a unique code is used (e.g., 0x0100 for Left Ctrl).

§Usage

  • Use scancode_to_keysym to convert a scancode to a symbolic key value.
  • Use scancode_to_ascii to convert a scancode to an ASCII byte (if possible).

§Limitations

  • Only Set 1 scancodes are supported.
  • Extended keys (E0/E1 prefix) and key release events are not handled here.
  • This table is designed for US QWERTY layout.

§Safety

This module is #![no_std] and suitable for use in kernel/bootloader code.

Structs§

Keysym
Symbolic representation of a key (keysym).

Functions§

scancode_to_ascii
Convert a PS/2 Set 1 scancode to an ASCII byte, if possible.
scancode_to_keysym
Convert a PS/2 Set 1 scancode to a Keysym.