/home

Just enough keyboard handling infos

Wed, 25 Dec 2024

Testing

My own testing is done through kbtest.c in a single Watcom C file.
There is no key buffering, but has a simplified extended key management and it ensure the CTRL-ALT-DEL key combination preserve the reboot capability in case of program crash ;)

References

Archives are from hornet.org

In keyb.zip archive, the KEYBOARD.TXT is a very good and complete introduction to the keyboard mechanism.

I think most of the above code make the assumption of a PC AT using the Intel 8042 chip as the keyboard controller.

Details about the 8042:

Scan codes:

And last but not least, the StackOverflow forum: https://stackoverflow.com/questions/40961527/checking-if-a-key-is-down-in-ms-dos-c-c

IBM PC and XT compatibles

On the IBM PC and XT and compatibles, you MUST clear the keyboard after reading the scancode by reading the value at port 0x61, flipping the 7th bit to a 1, and writing that value back to port 0x61. After that is done, flip the 7th bit back to 0 to re-enable the keyboard.

status = inp(0x61);         // get the current settings
scan_code = inp(0x60);      // get the scancode waiting in the output buffer
outp(0x61, status | 0x80);  // set the 7th bit of PPI port B (clear keyboard)
outp(0x61, status);         // clear the 7th bit of the PPI (enable keyboard)