How do I detect arrow keys pressed using curses in C?

后端 未结 3 1040
再見小時候
再見小時候 2020-12-10 02:29

In trying to get input from the arrow keys via curses (ncurses) it won\'t catch as KEY_UP etc. I used the keypad function with a true argument but getch still returned an e

3条回答
  •  渐次进展
    2020-12-10 02:54

    Standard (VT100-like) terminals send a sequence of characters when the arrow keys are pressed. You just have to keep track of whether or not these are pressed in sequence. Here are the char's to watch for:

    Down Arrow  0x1B 0x5B 0x42
    Left Arrow  0x1B 0x5B 0x44
    Right Arrow 0x1B 0x5B 0x43
    Up Arrow    0x1B 0x5B 0x41
    

提交回复
热议问题