0

However, ubuntu keyboard settings are responsive when I use the graphic testing screen.

The following code indicates that KEY_A1 is not detected, but you can see I have invoked keypad() and everything else responds on my machine normally. The keypad is detected as expected when numlock is on.

I have a toshiba satellite 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()
JoriO
  • 1,050
  • 6
  • 13

0 Answers0