LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-14-2001, 07:55 AM   #1
kaleeswarans
LQ Newbie
 
Registered: Apr 2001
Location: india
Posts: 1

Rep: Reputation: 0
Wink


g++ or gcc in debian linux. No curses.h or ncurses.h I have a menu of seven options. I want user to pres the arrow keys and navigate the options. I don know how to trap an arrow key pressed by the user. getchar() required a press of the enter key. Any other way around? No Xwindows please. This is pure character based menu (just like the foxpro PROMPT type)

thank you for anyhelp
kali
 
Old 07-25-2003, 05:09 PM   #2
MacKtheHacK
Member
 
Registered: Jul 2003
Location: Boston, MA, USA
Distribution: RedHat, SuSE, Gentoo, Slackware, Mandrake ...
Posts: 111

Rep: Reputation: 15
It sounds like you're trying to process input character by character, right? But the problem is, standard input is line buffered, which means that your program doesn't receive any input from the device until the user has entered an entire line. You need to set standard input to be unbuffered, so that you get each character as it is typed. What you need to do is set the terminal device's CBREAK flag, and turning off echoing would be a good idea too.

But you really don't want to do that directly yourself, because you would create a lot of problems for your code to handle. For example, those arrow keys send escape sequences of several characters, and you would have to know how many to read in. Also, different terminals use different sequences for the arrow keys. Fortunately, all these problems have been solved. What you should be using is "ncurses" (do a "man ncurses" to get started). This is a terminal-independent, text-based display package. While it's main focus is on creating output on text terminals, it also handles all the details of input processing for you, which is what you're after. It provides functions such as cbreak() and noecho() to do the things you want. See curs_inopts(3X) for more details.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
trapping packets mohit_garg Linux - Networking 6 07-10-2005 06:29 PM
catching a keypress on X MD3 Programming 0 02-14-2005 03:07 PM
emulating a keypress burglus Programming 2 01-29-2005 06:45 AM
navigating kde..... c0rderr0y Linux - Hardware 2 03-06-2004 04:30 PM
Trapping keystrokes in C k4zau Programming 3 03-09-2003 02:13 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:22 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration