Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c

linux

solaris

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.

like image 501
Bahaa Zaid Avatar asked Feb 20 '09 02:02

Bahaa Zaid


2 Answers

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

like image 147
Steve Weet Avatar answered Sep 28 '22 00:09

Steve Weet


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

like image 35
dmityugov Avatar answered Sep 28 '22 01:09

dmityugov