LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Recognizing up arrow key in C programs (https://www.linuxquestions.org/questions/programming-9/recognizing-up-arrow-key-in-c-programs-748500/)

leonardo6023 08-18-2009 02:07 PM

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

orgcandman 08-18-2009 02:57 PM

Quote:

Originally Posted by leonardo6023 (Post 3648394)
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.

Hko 08-18-2009 03:13 PM

Or use the ncurses library.
See this thread for some links: http://www.linuxquestions.org/questi...t-keys-745498/

leonardo6023 08-19-2009 08:24 AM

thanks... the link was really helpful :)


All times are GMT -5. The time now is 09:40 AM.