How to detect that arrow key is pressed using C under Linux or Solaris?

戏子无情 提交于 2019-12-19 19:00:11

问题


What is the best way to detect in a C program that arrow key is pressed under Linux or Solaris?

As I know there is no standard C function that can do it. I don't want to use int86 function. I need to do it in a portable way.

Edit: I am asking about console applications.


回答1:


You should look at the curses/ncurses library which will give you advanced screen and keyboard handling for console applications.

There is a lot of documentation available for curses, which is an extensive library.

There is a write-up on this very question available here




回答2:


I believe your program should switch into non-canonical mode to be able to read special characters




回答3:


If you wanted to do this without using something like SDL, you should look into the select() statement and how to use it to read from console input.



来源:https://stackoverflow.com/questions/568035/how-to-detect-that-arrow-key-is-pressed-using-c-under-linux-or-solaris

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