Chinaunix首页 | 论坛 | 博客
  • 博客访问: 613333
  • 博文数量: 144
  • 博客积分: 5037
  • 博客等级: 大校
  • 技术积分: 1581
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-30 21:49
文章存档

2010年(16)

2009年(128)

分类: LINUX

2009-04-11 09:45:28

keypress.h文件

#ifndef _INCLUDE_KEYPRESS_H_
#define _INCLUDE_KEYPRESS_H_

#include <termios.h>

void set_keypress(void);
void reset_keypress(void);

#endif

keypress.c文件

#include <termios.h>

//===========================================================
//终端属性设置uart
//===========================================================
static struct termios old_settings;

void set_keypress(void)   //设置
{
    struct termios new_settings;

    tcgetattr(0, &old_settings);
    new_settings = old_settings;

    /* Disable canonical mode, and set buffer size to 1 byte */
    new_settings.c_lflag &= (~ICANON);
    new_settings.c_lflag &= (~ECHO);
    
    new_settings.c_cc[VTIME] = 0;
    new_settings.c_cc[VMIN] = 1;

    tcsetattr(0, TCSANOW, &new_settings);
    return;
}

void reset_keypress(void)//恢复
{
    tcsetattr(0, TCSANOW, &old_settings);
    return;
}

 

阅读(399) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~