unix - How to instantly react to key pressing in C? -


i'm trying call function when user presses key, sending signal ctrl-c. idea doing something, in while loop, , actively listen for, say, 'f' key being pressed. when pressed, program stop performing loop , else because 'f' key pressed.

is there way customize signal mapping? didn't have luck this. there seemed 1 or 2 available signals customization, need 3.

if use getchar(), user needs press 'f' key , press enter key. them press 'f' key , not have press enter key.

it similar using unix's more program user can press space bar go through pages.

any appreciated!

if reason not ncurses, can try following.

you can use separate thread uses select() on stdin performs read() on stdin , parses user input; if key looking for, send signal (i.e. user1 or user2 unused) main thread. in signal handler, perform whatever operation looking on interrupt. note doing means code must interruptible interrupt not break computation.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -