Curses getting arrow keys

旧巷老猫 提交于 2019-11-30 11:13:45
Paul Franz

I found the same problem on Mac OS X. But it was resolved by adding the following:

keypad(stdscr, TRUE);

I was storing getch() calls as char's when they were supposed to be int's. Works perfectly after the switch.

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!