开发者

Command-line C & keyboard shortcut (in Mac OS)

How can I exec开发者_C百科ute a command when user press a key in a command-line C application? Is it possible when window isn't focused


Depends on the program itself, you could do either of those:

  1. block on unbuffered getc you get the key strokes as they come and not when users hits return.

  2. create some sort of event loop, using select/epoll or event framework like (libevent/libev) and get a callback whenever a user hits a key.

  3. use a toolkit like ncurses which provides a pseudo graphical command line interface and an event loop.

  4. if the keys you're interesting in capturing are things like CTRL+C, you need signal handlers.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜