免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1071 | 回复: 0
打印 上一主题 下一主题

《Linux 程序设计入门》 第四版 §6.7 小键盘 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-12-15 09:54 |只看该作者 |倒序浏览

§6.7  小键盘

       小键盘中的字符要用字符串来表示,且不通的终端还有不通表示方法,识别起来要困难一些。Curses把它存储在terminfo中,curses.h定义了KEY_来表示逻辑键。
       序列到逻辑键转换的开启:
#include
int keypad(WINDOW
*window_ptr, bool keypad_on);

         使用keypad模式的3个注意点:
❑转移序列有时间依赖性,注意网络影响。
❑ 注意按键适当的时间间隔
❑ 同样的多个键可能有不通功能。

# cat keypad.c
/*  Having initialized the program and the curses
library, we set the Keypad mode TRUE.  */

#include
#include
#include

#define
LOCAL_ESCAPE_KEY    27

int main()
{
    int key;

    initscr();
    crmode();
    keypad(stdscr, TRUE);

/*  Next, we must turn echo off
    to prevent the cursor being moved when some
cursor keys are pressed.
    The screen is cleared and some text
displayed.
    The program waits for each key stroke
    and, unless it's q, or produces an error,
the key is printed.
    If the key strokes match one of the
terminal's keypad sequences,
    then that sequence is printed instead.  */

    noecho();

    clear();
    mvprintw(5, 5, "Key pad demonstration.
Press 'q' to quit");
    move(7, 5);
    refresh();

    key = getch();
    while(key != ERR && key != 'q') {
        move(7, 5);
        clrtoeol();

        if ((key >= 'A' && key
            (key >= 'a' && key
            printw("Key was %c",
(char)key);
        }
        else {
            switch(key) {
            case LOCAL_ESCAPE_KEY:
printw("%s", "Escape key"); break;
            case KEY_END:
printw("%s", "END key"); break;
            case KEY_BEG:
printw("%s", "BEGINNING key"); break;
            case KEY_RIGHT:
printw("%s", "RIGHT key"); break;
            case KEY_LEFT: printw("%s",
"LEFT key"); break;
            case KEY_UP: printw("%s",
"UP key"); break;
            case KEY_DOWN:
printw("%s", "DOWN key"); break;
            default: printw("Unmatched -
%d", key); break;
            } /* switch */
        } /* else */

        refresh();
        key = getch();
    } /* while */

    endwin();
    exit(EXIT_SUCCESS);
}

               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/21908/showart_1721303.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP