简体   繁体   English

诅咒得到箭头键

[英]Curses getting arrow keys

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 returns an escaped sequence. 在尝试通过curses(ncurses)从箭头键获取输入时,它不会捕获KEY_UP等。我使用带有true参数的键盘函数但getch仍然返回一个转义序列。 How do I sift through the values returned by getch() and grab the arrow keys specifically? 如何筛选getch()返回的值并专门抓取箭头键?

I was storing getch() calls as char's when they were supposed to be int's. 我将getch()调用存储为char,因为它们应该是int的。 Works perfectly after the switch. 切换后工作完美。

我在Mac OS X上发现了同样的问题。但是通过添加以下内容解决了这个问题:

keypad(stdscr, TRUE);

Standard (VT100-like) terminals send a sequence of characters when the arrow keys are pressed. 当按下箭头键时,标准(VT100类)终端发送一系列字符。 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM