红联Linux门户
Linux帮助

转载

发布时间:2011-12-02 22:50:26来源:红联作者:JokerHat
[i=s] 本帖最后由 JokerHat 于 2011-12-2 22:51 编辑 [/i]

[code] #include
#include
#include /* Please reference the manpage (man termios) for more details. */
int mygetch(void)
{
int ch;struct termios oldt;
struct termios newt;
tcgetattr(STDIN_FILENO, &oldt);
newt = oldt;/** Unset the CANONICAL mode, in which input is available immediately,* and the ECHO mode.*/
newt.c_lflag &= ~(ICANON | ECHO);
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
ch = getchar();
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
return ch;
}
int main(int argc, char * argv[])
{
printf("Press any key to continue...\n");
mygetch();
return 0;} [/code]
文章评论

共有 2 条评论

  1. crazyrhino 于 2012-03-27 15:24:04发表:

    这个模拟的getchar()还比较靠谱,顶一个

  2. sonr 于 2011-12-03 08:51:05发表:

    路过