Hi,
Otter wrote:And that's not all. You have to notice keys like shift or alt, there are some advanced key codes following the scan code 0xE0 and so on ...
Sometimes the keyboard controller sends for example 5 scan codes for one key.
Yes, but that's not all...
There's different keyboards for different regions (French, German, Russian, Japanese, etc), and most modern OSs use Unicode instead of ASCII to support this.
For some languages/keyboards there's a huge number of characters (Japanese, Chinese, Korean, etc). For these there's usually some sort of visual tool between the keyboard driver and the application (an IME or Input Method Editor). For a (probably bad) English example, it's like pressing the 'H' key and getting a list of words that begin with 'H', and then either selecting the word 'Hello" from the list or pressing 'E' to get a refined list, until you have the correct character (realising that the English word "Hello" would be a single character, rather than a series of letters).
Then all modern OS's allow multiple applications to run at the same time, and let the user switch between them (e.g. alt+tab in a GUI, or alt+Fn for Unix style virtual terminals).
There's also "magic" keypresses (that are never sent to any application). This usually includes the "control+alt+delete" combination, but can include others (alt+tab, control+alt+backspace, alt combined with numbers on the numerics keypad, etc).
Further, for most systems "getchar()" can be redirected, so that it gets it's data from a file, from a serial port, from another program, etc - it's the same as "getc(stdin)" (where "stdin" isn't always the keyboard).
Lastly, polling always sucks because it's a waste of CPU time - for e.g. if one task is waiting for a key to be pressed, why not run other tasks until a key is pressed? In this specific case it's much worse - if "getchar()" isn't called in a tight loop you'll get lost keypresses, you won't be able to tell if the data from port 0x60 is from the keyboard or the mouse, and you won't be able to write a mouse driver at all.
Cheers,
Brendan