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