Thread: How to read arrow keys in Linux?

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    13

    How to read arrow keys in Linux?

    Hi,

    I want to know how to read the arrow keys in Linux. I'm making a test with a program similar to less and I want to use up & down keys for moving through the file, but there's no ASCII code for these keys.

    Thanks in advance.

  2. #2

  3. #3
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    You can also use the series of ascii codes produced from the keys.
    Code:
    int ch;
    while ( (ch=getch()) != EOF )
      printf("%x ", ch);
    Put that in a program and look at the output when you hit the different keys.

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Assuming of course that your compiler actually has getch. To fully answer the question, there is no portable way to read "specially abled" keys from the keyboard, because there is no way to read a single keystroke.

    However, if there were, I bet it would be covered in the FAQ, like the origional question is!

    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Opps I meant getchar() But of course when I was testing for that I used that getch() I posted in the linux forum

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Arrow Keys
    By DeepFyre in forum C++ Programming
    Replies: 1
    Last Post: 10-12-2004, 04:16 PM
  2. Using the arrow keys
    By Punkture in forum C Programming
    Replies: 8
    Last Post: 05-31-2003, 04:25 PM
  3. How To Check Arrow Keys?
    By Bordonel in forum Game Programming
    Replies: 3
    Last Post: 06-15-2002, 09:52 AM
  4. msdos arrow keys?
    By seditee in forum Game Programming
    Replies: 3
    Last Post: 05-07-2002, 11:29 PM
  5. Arrow keys in console?
    By SyntaxBubble in forum C++ Programming
    Replies: 3
    Last Post: 02-02-2002, 06:12 PM