LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-18-2009, 02:07 PM   #1
leonardo6023
LQ Newbie
 
Registered: Aug 2009
Posts: 3

Rep: Reputation: 0
Recognizing up arrow key in C programs


Hello
I am using gcc 4.3.2
i was wondering how i would realize an up/down/left/right arrow key press in realtime during execution of my C program in the terminal.
Also, if it would be possible to realize the key stroke without emptying the input buffer using a /n or something of the sort.
Thanks
 
Old 08-18-2009, 02:57 PM   #2
orgcandman
Member
 
Registered: May 2002
Location: new hampshire
Distribution: Fedora, RHEL
Posts: 600

Rep: Reputation: 110Reputation: 110
Quote:
Originally Posted by leonardo6023 View Post
Hello
I am using gcc 4.3.2
i was wondering how i would realize an up/down/left/right arrow key press in realtime during execution of my C program in the terminal.
Also, if it would be possible to realize the key stroke without emptying the input buffer using a /n or something of the sort.
Thanks
You'll need to use termio to set the tty into character mode instead of line mode. Then when you read(fd, &c, 1); you'll get the characters as they're pressed rather than when someone presses return. After that, it's a simple matter of handling the character codes you receive.
 
Old 08-18-2009, 03:13 PM   #3
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Or use the ncurses library.
See this thread for some links: http://www.linuxquestions.org/questi...t-keys-745498/
 
Old 08-19-2009, 08:24 AM   #4
leonardo6023
LQ Newbie
 
Registered: Aug 2009
Posts: 3

Original Poster
Rep: Reputation: 0
thanks... the link was really helpful
 
  


Reply



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
holding down arrow key doesn't work in acroread burak1000 Linux - Software 7 08-13-2009 03:35 AM
Tab Key and arrow key zillah Solaris / OpenSolaris 12 05-26-2005 02:51 PM
Arrow Key mapping lazlom AIX 5 06-21-2004 03:32 PM
down arrow key problem rcbob Linux - Software 0 06-05-2004 07:58 PM
Detecting Arrow Key Presses in C / C++ BooKA. Programming 8 04-07-2004 06:10 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:53 PM.

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
Open Source Consulting | Domain Registration