开发者

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

开发者 https://www.devze.com 2023-01-05 20:04 出处:网络
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 focusedDepends on the program itself, you could do either of those:

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

精彩评论

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