Home > Software engineering >  How to get special keys with BIOS interrupts
How to get special keys with BIOS interrupts

Time:02-28

I'm writing a real mode OS, and I'm wondering if there is a way to read keys such as function keys, arrow keys, control, alt, and the like with BIOS interrupts? I appreciate any help you can provide.

CodePudding user response:

The keyboard BIOS can help you with this.

Code like

mov ah, 00h
int 16h     ; -> AX

will wait for a keypress and return to you with the ASCII code of the key in AL and the scancode of the key in AH.
For function keys, arrows and the like, you would only look at the scancode because for most of these keys the ASCII code will be zero.

To know about the state of the ALT keys, CTRL keys, or others you can use functions 02h or 12h. Alternatively, you can inspect the BIOS variables in low memory at 0040:0017h and 0040:0018h.


ps I can't currently post comments (browser issue) ...

If the above code produces AX=1E01h it would indeed mean that the user pressed CTRLA.
Care has to be taken with certain ALT key combinations were the code that is returned in AX could depend on whether the keyboard is QWERTY or AZERTY. ALTA, ALTQ, ALTZ, ALTW, ALTM.

  • Related