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

后端 未结 7 1436
挽巷
挽巷 2020-12-10 03:11

How to get Ctrl, Shift or Alt with getch() ncurses ?
I cannot get it work to get Ctrl, Shift or

7条回答
  •  -上瘾入骨i
    2020-12-10 03:35

    At least for the control modifier there is a simple solution. Curses had been derived from vi source code, in which you find the following (see https://github.com/n-t-roff/ex-1.1/blob/master/ex.h line 77 and https://github.com/n-t-roff/ex-1.1/blob/master/ex_vops.c line 445):

    #ifndef CTRL
    #define CTRL(c) ((c) & 037)
    #endif
    
    switch(getch()) {
    case CTRL('r'):
        /* key ctrl-r (i.e. ^R) pressed */
    

    Dependend on used includes CTRL may or may not already been defined in your code.

提交回复
热议问题