> Is there any way to detect this without using winAPI or any other standard APIs???
No there isn't.
Standard C doesn't know about keyboards, mice, screens or other advanced stuff like that.
It has an input stream, which is usually buffered, so there goes the "immediate" requirement.
It also has no control over what the environment chooses to stuff into that input stream. So whilst some keyboard keys make it (say 'A'), others do not (say a cursor key). Likewise, mouse positions are completely foreign.
So at the very least, you have to use whatever your OS / Platform gives you. So for example, to do this in a win32 console, you would use functions like ReadConsoleInput
If you don't like having a big black rectangle in the middle of the screen, then you're going to have to look at writing say a service (with perhaps its own little icon in the system tray), making use of hook functions.
>>>>The function you posted will return the ascii code, not the scan codes
I still say that, it returns, scan code
try with any character key like 'A','s', etc.
& guess, they r same for any keyboard!
int 16 returns the scan code in ah and the ascii value in al. If you really want the ascii value then get it from al. When the value of ah is 0 that means someone hit one of the special keys, such as function and arrow keys. In that case you have to call int 16 a second time to get its values. The ascii value of special keys are the same as normal keys. There are several ways to handle that -- one way is to add 255 to the ascii value of special keys, another way I've seen is to make them a negative value. You have to do that so that the rest of the program knows how to interpret the value returned by that function.