0

这是一个无需按回车即可获取字符的代码。

int getch(FILE *cmd)
{
    int ch;
    struct termios buf;
    struct termios info;

    tcgetattr(0, &info);
    buf = info;
    buf.c_lflag &= ~(ICANON | ECHO); // noncanonical
    buf.c_cc[VMIN] = 1;
    buf.c_cc[VTIME] = 0;

    // buf.c_cc[VINTR];
    // buf.c_cc[VKILL];

    tcsetattr(0, TCSAFLUSH, &buf);
    ch = getc(cmd);
    tcsetattr(0, TCSAFLUSH, &info);

    return ch;
}

在这段代码中,如何在非规范模式下使用中断/终止信号?

4

1 回答 1

1

您应该尝试进行c_iflag适当的修改。见BRKINTIGNBRK标志。

于 2014-11-04T11:45:07.197 回答