【发布时间】:2016-04-19 11:31:46
【问题描述】:
代码
while (1)
{
keycode = key_hook();
if (keycode == SPACE || keycode == BKSPACE)
{
render_again = 1;
}
if (keycode == ESC)
break;
if (render_again)
{
render_again = 0;
render(all);
}
dprintf(1, ""); //I have no idea why this prevents the program from freezing
}
int key_hook()
{
char buffer[4];
read(0, buffer, 4);
return (*(unsigned int *)buffer);
}
好的,所以这段代码处理屏幕上文本的重绘。某些文本行使用termcaps (tputs(tgetstr("us, NULL")......) 加下划线或突出显示。一切都打印得很好,但是在第一次重绘文本之后,while 显然会冻结,除非存在 dprintf/printf。 key_hook 函数只是从stdin 中读取4 bytes 并将它们转换为int。
【问题讨论】:
-
发布
key_hook函数可能是个好主意... -
stdin 中的 4 个字符如何等同于按键?我假设这个程序不是从 tty 读取的?
-
是的,但我需要 4 个字符用于特殊键,例如箭头键,例如这样的代码 ^[[C
-
不确定我是否关注。我认为
^[是ESC的视觉表示... -
从终端读取时,箭头键由 4 个字符组成,这是我从测试中扣除的,它工作正常,直到我引入了冻结它的 termcaps 部分