Hi guys, this is what i wrote:
if(kbhit()){
a=[some function returning last key pressed];
doaction(a);
}
doaction() is a function i wrote but it doesnt matter. What does matter is how to get a character from keyboard without interrupting execution just like getch() does. I am thinking of making a game so i need the game not to wait for the player to press a key, the game should go on. By using kbhit() i know whether a key was pressed, but i dunno which key. That is the problem i am currently facing. If there is something i didn't write in a clear way, please let me know it.
HINT:
I am also in the search of answer of the same problem. However what i
know till now is that by using signal handling mechanism provided by operating system, we come to the answer.
Signals in the system can be catogorised as synchronous signal and
asynchronous signals. whenever program encounters a faulty instruction such as divide by zero, trap occurs in the system. System then, in turn, generates
signal to the program informing of the faulty instructions and then terminates the program. This signal is the one that is generated by faulty instruction in the program itself hence called as synchronous signal. On the other hand when
signal is generated as a result of an event ( such as pressing key ) external to the program . It is called as asynchronous signal.
There are another issues concerning how program should handle
such signal. Amongst them are simply ignore signal, perform action according to system defined function such as terminating the program, Or handle it according to code defined by application programmer like you and me.
I suggest you further to read book Operating System Principles by
Galvin for motivation purpose (Second chapter specifically, where this mechanism is illustrated in a program). Then try for signal handling mechanism from the books you may pursue later.
Nowadays I am busy with my schedule and not able to spend time
for reading so I think you may proceed further and reply me for the answer.