Home > Software engineering >  How to read Ctrl C as input
How to read Ctrl C as input

Time:11-24

(in Linux)

The methods I found all use signal .

Is there no other way? Is there anything I can do to make the terminal put it into the input buffer?

CodePudding user response:

In order to "read CTL C as input" instead of having it generate a SIGINT it is necessary to use tcsetattr() to either clear cc_c[VINTR] or clear the ISIG flag as described in the manual page that I linked to, here.

You will need to use tcgetattr, first, to read the current terminal settings, adjust them accordingly, then tcsetattr to set them.

You should make sure that the terminal settings get reset to their original defaults when your program terminates, it is not a given that the shell will reset them to default, for you.

  • Related