Small Help!

This is a discussion on Small Help! within the C Programming forums, part of the General Programming Boards category; I need to read in the Arrow Keys (up,down, left, right) from the keyboard. There are no standard ASCII values ...

  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    134

    Small Help!

    I need to read in the Arrow Keys (up,down, left, right) from the keyboard. There are no standard ASCII values for these keys (atleast not that I am aware of). I am working on Linux OS. My keyboard input function uses getchar().

    Any suggestions?

    Thanks,

  2. #2
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    Gaaah! Search the forum and read the FAQ!
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  3. #3
    Registered User divineleft's Avatar
    Join Date
    Jul 2006
    Posts
    158
    Quote Originally Posted by nkhambal
    I need to read in the Arrow Keys (up,down, left, right) from the keyboard. There are no standard ASCII values for these keys (atleast not that I am aware of). I am working on Linux OS. My keyboard input function uses getchar().

    Any suggestions?

    Thanks,
    ncurses

  4. #4
    and Nothing Else Matters
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    117
    arrow keys have ascii equivalents. try experimenting using getch()
    It is not who I am inside but what I do that defines me.

  5. #5
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  6. #6
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    arrow keys have ascii equivalents. try experimenting using getch()
    And why do you assume he uses Borland compiler? (if there even is one for Linux)
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  7. #7
    Registered User
    Join Date
    Apr 2005
    Posts
    134
    I can not use ncurse. And I do not have conio.h on linux to use getch(). I have to use getchar() somehow. Is there a way to work it out without getch().

    The faq posted was using getch(). I can't use it. I couldn't find much on google.

  8. #8
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    And why do you assume he uses Borland compiler?
    We don't, but hey, it's VERY likely... Or one could try *curses. (ncurses, pdcurses...)

    nkhambal: well arrow key values appear to be very fairly distributed across systems. On Linux the leading byte appears to be 0, on my XP it's 224. It might be easier to use more consistent characters like [wasd] or [8456]. You could try allowing the user to set the values, but then this would not be cnvenient in small code snippets. The best solution is to interface your platform's native API.

    getchar() uses buffered input, meaning whatever is input is filtered and processed by the system first. The system will take all arrow keys and use them for other things (say, letting the user move the caret around when typing in text) and the result is standard functions like getchar() and fgets() don't get these special characters. You have to bypass the buffering using platform-dependant methods.


    P.S: It might be interesting to collect (eg. a survey) various compiler and env usage statistics for programmers of varying proficiency levels and occupations, and comparing them. Any takers?
    Last edited by jafet; 11-11-2006 at 06:21 AM.
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to split long programe in small files
    By umeshjaviya in forum C Programming
    Replies: 11
    Last Post: 04-15-2008, 02:45 AM
  2. Small HTTP proxy
    By zacs7 in forum Networking/Device Communication
    Replies: 8
    Last Post: 09-11-2007, 03:53 AM
  3. want to make this small program...
    By psycho88 in forum C++ Programming
    Replies: 8
    Last Post: 11-30-2005, 01:05 AM
  4. FILES in WinAPI
    By Garfield in forum Windows Programming
    Replies: 46
    Last Post: 10-02-2003, 06:51 PM
  5. yhatzee, small straight
    By uglyjack in forum C++ Programming
    Replies: 2
    Last Post: 06-13-2002, 03:09 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21