0

但是,当我使用图形测试屏幕时,ubuntu 键盘设置会响应。

以下代码表示未检测到 KEY_A1,但您可以看到我已调用 keypad() 并且其他所有内容都在我的机器上正常响应。numlock 开启时,按预期检测到键盘。

我有一个东芝卫星L755

#include <ncurses.h>
#include <stdio.h>

struct dude{
    int x, y, sym;
};

int main() {

    char str[80];
    struct dude theDude;
    theDude.sym = '@';
    theDude.x = 10;
    theDude.y = 10;
    // Start up curses for character at a time input without echo.
    initscr();

    int ch = 0, i = 0, j = 0;

    cbreak();
    noecho();
    nonl();
    intrflush(stdscr, FALSE);
    keypad(stdscr, TRUE);
    curs_set(0);
    //  echo(); //let terminal echo when program is exited
    //  nocbreak();
    //  nl();
    do{
        clear();
        for(i = 0; i < LINES - 1;i++){
            for(j = 0;j< COLS;j++){
                mvaddch(i, j, '.');
            }
        }
        mvaddch(theDude.y, theDude.x, '@');
        mvaddstr(LINES - 1, 0, keyname(ch));
        if(has_key(KEY_A1)){
            addstr(" A1 Detected");
        }
        else
            addstr(" No A1 bro!");    
        switch(ch = getch()){
            case KEY_A1:
                --theDude.y;
                --theDude.x;
                break;
            case KEY_UP:
                --theDude.y;
                break;
            case KEY_A3:
                ++theDude.x;
                --theDude.y;
                break;
            case KEY_LEFT:
                --theDude.x;
                break;
            case KEY_B2:
                break;
            case KEY_RIGHT:
                ++theDude.x;
                break;
            case KEY_C1:
                ++theDude.y;
                --theDude.x;
                break;
            case KEY_DOWN:
                ++theDude.y;
                break;
            case KEY_C3:
                ++theDude.y;
                ++theDude.x;
                break;
        }// ch switch for character input
    }while(ch != 'q');

    endwin();

    return 0;

} // main()
4

0 回答 0