getch(), up down left right

This is a discussion on getch(), up down left right within the C Programming forums, part of the General Programming Boards category; if getch() only returns one value, how do you get the return values for the up, down, left and right ...

  1. #1
    Unregistered
    Guest

    Arrow getch(), up down left right

    if getch() only returns one value, how do you get the return values for the up, down, left and right keys? i mean, they are like 0+75 and 0+72, etc. does anyone know?

    also, how can you capture a keypress without the program pausing and waiting for it?

    bennyandthejets

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,494
    > how do you get the return values for the up, down, left and right keys
    Call getch twice

    ch = getch();
    if ( ch == 0 ) ch = 256 + getch();

    Normal keys are in the range 0..255
    Extended keys are in the range 256..511

    > how can you capture a keypress without the program pausing and waiting for it?
    Depends on your OS and compiler

  3. #3
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683
    well the values for up, down, left , right are as follows.. But i do not know the correct order

    0x48
    0x50
    0x4d
    0x4b


    Well you can use it like this

    int ch;
    ch=getch();

    if(ch==0x48)
    move left or something


    ANd to get a key without waiting.. If you are using Windows and if your compiler supports it.. Include conio(i guess)

    use the function kbhit()
    Eg

    if(kbhit())
    {

    ch=getch();
    }
    else
    do something


    So now untill a key is pressed something else can be done..

  4. #4
    Registered User red_baron's Avatar
    Join Date
    May 2002
    Posts
    274
    ¿Red Baron?

    "Imagination is more important than knowledge"
    -Albert Einstein (1879-1955)

    Check out my games!

    [code] /* dont forget code tags! */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  2. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  3. pointer to array of objects of struct
    By undisputed007 in forum C++ Programming
    Replies: 12
    Last Post: 03-02-2004, 03:49 AM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM
  5. Please help me
    By teedee46 in forum C++ Programming
    Replies: 9
    Last Post: 05-06-2002, 11:28 PM

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