How can I execute a command when user press a key in a command-line C application? Is it possible when window isn't focused
A:
Depends on the program itself, you could do either of those:
block on unbuffered getc you get the key strokes as they come and not when users hits return.
create some sort of event loop, using select/epoll or event framework like (libevent/libev) and get a callback when ever a user hits a key.
use a toolkit like ncurses which provides a pseudo graphical command line interface and an event loop.
if the keys you're interesting in capturing are things like CTRL+C, you need signal handlers.
miedwar
2010-07-07 14:48:44