Ncurses的和实时(在C,UNIX实现) [英] Ncurses and realtime (implemented in C, unix)

查看:144
本文介绍了Ncurses的和实时(在C,UNIX实现)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现使用中的ncurses C.我必须显示当前时间(时间必须更新每一秒)和我while循环看起来像这样

I am trying to implement a game using ncurses in C. I have to show the current time (the time must update each second) and my while loop looks like this

while(1)
{
    clk = time(NULL);
    cur_time = localtime(&clk);
    mvprintw(0,1,"%d %d %d",cur_time->tm_hour,cur_time->tm_min,cur_time->tm_sec);
    int key = getch()
    //other stuff
}

我的问题是,当我preSS一个关键的时间只会刷新。它是一种方法,使时间刷新,而不需要pressing一个键(在相同的时间来实现这一点)?

My problem is that the time will refresh only when I press a key. Is it a way to make the time refresh without the need of pressing a key (and to implement this in the same while)?

推荐答案

有一对夫妇的功能,你可以使用:

There are a couple of functions you could use:


  1. NODELAY

  2. 超时

INT NODELAY(WINDOW *赢,布尔BF);

int nodelay(WINDOW *win, bool bf);

组BF真正使残培()无阻塞

Set bf true to make getch() non-blocking

无效超时(INT延迟);

void timeout(int delay);

延迟是以毫秒为单位,因此,如果你把它设置为1000,该残培将第二次后超时。

Delay is in milliseconds, so if you set it to 1000, the getch will timeout after a second.

在这两种情况下的getch将返回ERR如果没有输入。

In both cases getch will return ERR if there is no input.

这篇关于Ncurses的和实时(在C,UNIX实现)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆