When a key is pressed or released, the keyboard sends
the information about this key and the action (pressed or relased)
to the CPU. This data is proccessed by the B.I.O.S. interrupt '9H'
which sends the translated information to programs.
Just put your key detection function over the BIOS keyboard handler
and your code will be called every time a key event occurs. The keyboard
event can be read from port 60h. It's a byte size port and is divided
in to the Scancode and the Key Event
+---+---+---+---+---+---+---+---+
| .7 | .6
| .5 | .4
| .3 | .2
| .1 | .0
|
+---+---+---+---+---+---+---+---+
Key | Scan Code
Evnt|
The Scancode is 7-bits and represents the key ID. The key event
is the most significant bit (bit-7). When this is true the key was
released, otherwise the key was pressed. You must control whether
keys are pressed or relased by yourself.