Thread: arrow keys in linux

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    35

    arrow keys in linux

    How I can read when the user press an arrows keys in c/c++?

    thx
    Lollo

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    As long as you are reading the "raw keys", you should be able to read out the escape-sequence of the keys. In normal mode, you are reading the "cooked" result of the input, so you don't get individual key-presses, but rather the input that the IO subsystem has "cooked" for you.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    35
    can you show me a snippet which do that I need?
    thx

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    It's worth noting here that the escape sequences are "multicharacter" sequences, so you will either have to read multiple characters with a timeout when there's nothing more to read, or parse the input intelligently.

    Another option is to use some sort of curses library - ncurses for example.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Jan 2008
    Posts
    35
    Ok...I use ncurses...

  6. #6
    Registered User
    Join Date
    Jan 2008
    Posts
    35
    I'm using eclipse to develope...using ncurser when use the function
    "initscr"
    I get
    "Error opening terminal: unknown."

    ...why?

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Not sure, what terminal type is it reporting?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  8. #8
    Registered User
    Join Date
    Jan 2008
    Posts
    35
    eclipse use his embedded console...perhaps is this the problem

  9. #9
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by lollobrigido View Post
    eclipse use his embedded console...perhaps is this the problem
    Probably - try running your application in it's own window.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Movement with arrow keys
    By louis_mine in forum C Programming
    Replies: 3
    Last Post: 02-06-2005, 04:35 PM
  2. How to read arrow keys in Linux?
    By edugarcia in forum C Programming
    Replies: 4
    Last Post: 11-09-2004, 03:20 PM
  3. Ascii code for arrow keys
    By beginner in forum C Programming
    Replies: 1
    Last Post: 11-07-2002, 01:29 PM
  4. msdos arrow keys?
    By seditee in forum Game Programming
    Replies: 3
    Last Post: 05-07-2002, 11:29 PM
  5. Arrow keys
    By Nutshell in forum C Programming
    Replies: 5
    Last Post: 03-27-2002, 11:49 AM