This is a patch that worked for the Bochs BIOS. The code is similar.
The important part is the keycode. DOSRMX needs this for console switching.
The other part is a hook. I have key presses; key releases should be done too. I don't know what uses this, but it is a standard BIOS feature.