如何在linux下用C语言实现字幕的左右滚动
答案:2 悬赏:70 手机版
解决时间 2021-03-11 21:50
- 提问者网友:不要迷恋哥
- 2021-03-11 12:44
如何在linux下用C语言实现字幕的左右滚动
最佳答案
- 五星知识达人网友:蕴藏春秋
- 2021-03-11 13:03
用死循环 每次将显示的字幕删除然后把字幕往前移一位再显示 达到一定的距离后再一点一点删除之前的空格 给个判断条件退出即可 这样可以做到字幕的滚动
全部回答
- 1楼网友:舍身薄凉客
- 2021-03-11 13:10
自己写函数
#include
#include
static struct termios initial_settings, new_settings;
static int peek_character = -1;
void init_keyboard(void);
void close_keyboard(void);
int kbhit(void);
int readch(void);
void init_keyboard()
{
tcgetattr(0,&initial_settings);
new_settings = initial_settings;
new_settings.c_lflag |= icanon;
new_settings.c_lflag |= echo;
new_settings.c_lflag |= isig;
new_settings.c_cc[vmin] = 1;
new_settings.c_cc[vtime] = 0;
tcsetattr(0, tcsanow, &new_settings);
}
void close_keyboard()
{
tcsetattr(0, tcsanow, &initial_settings);
}
int kbhit()
{
unsigned char ch;
int nread;
if (peek_character != -1) return 1;
new_settings.c_cc[vmin]=0;
tcsetattr(0, tcsanow, &new_settings);
nread = read(0,&ch,1);
new_settings.c_cc[vmin]=1;
tcsetattr(0, tcsanow, &new_settings);
if(nread == 1)
{
peek_character = ch;
return 1;
}
return 0;
}
int readch()
{
char ch;
if(peek_character != -1)
{
ch = peek_character;
peek_character = -1;
return ch;
}
read(0,&ch,1);
return ch;
}
int main()
{
init_keyboard();
while(1)
{
kbhit();
printf("\n%d\n", readch());
}
close_keyboard();
return 0;
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯