cncurses

How to get Ctrl, Shift or Alt with getch() ncurses?


How to get Ctrl, Shift or Alt with getch() ncurses ?

Do I miss something in the man ?


Solution

  • Amazing how sometimes the right answer gets demoted, and answers that "authoritatively" give up get promoted... With a bit of creativity, key_name actually holds the right key to figuring this out, with one caveat - that SHIFT/ALT/CTRL are pressed with other keys at the same time:

    So you can now figure out the key codes for your switch(getch) statements, etc, by a simple snippet:

    ch = getch(); endwin(); printf("KEY NAME : %s - %d\n", keyname(ch),ch);
    

    and that's that. Think before definitively saying "can't". Maybe there's a way that's less obvious.