Thread: Using Arrows in Win 32 Console

  1. #1
    Registered User GreenCherry's Avatar
    Join Date
    Mar 2002
    Posts
    65

    Question Using Arrows

    When you use getch() what are the chars for the errors?

    EDIT: I'm using C++, MSVS
    Last edited by GreenCherry; 10-04-2002 at 09:30 AM.

  2. #2
    Registered User GreenCherry's Avatar
    Join Date
    Mar 2002
    Posts
    65
    bump
    I have a rabbit in my pants! Please be happy for me.

  3. #3
    Registered User Kirdra's Avatar
    Join Date
    Aug 2002
    Posts
    105
    I think you need to rephrase that question.

  4. #4
    Registered User red_baron's Avatar
    Join Date
    May 2002
    Posts
    274
    took me a long time to make this...
    ¿Red Baron?

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

    Check out my games!

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

  5. #5
    how would you use this?

    Would you just compare the int returned with the value provided?

    Does it work with getche()?

    I am using DEV, if that effects it.
    Compilers:
    GCC on Red Hat 8.1 (Primary)
    GCC on Mac OS X 10.2.4 (Secondary)

    Others:
    MinGW on XP

  6. #6
    Registered User red_baron's Avatar
    Join Date
    May 2002
    Posts
    274
    Code:
    <headers...>
    #include "keys.h"
    
    int main()
    {
       int keys;
       keys=my_getch();
       if (keys==K_LEFT)
       {
          printf("left key was pressed");
       }
       system("PAUSE");
       return 0;
    }
    
    
    int my_getch ()
    {
       int input=getch();
       if (input==224) 
          input=getch();
       else if (input==0)
          input=256+getch();
       return input;   
    }

    btw its been a lil while since i last programmed so there might be a small mistake havn't compiled yet should work with dev-c++ (waht i use)
    ¿Red Baron?

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

    Check out my games!

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

  7. #7
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    Code:
    #include <iostream>
    #include <stdlib.h>
    #include "keys.h"
    #include <conio.h>
    
    using namespace std;
    
    int move = 0;
    char key;
    int x = 0;
    int y = 0;
    
    int main()
    {
          
          do
           {
            key = getche();
            move = (char)key;
              if(move == K_UP)
               y--;
              else if(move == K_DOWN)
               y++;
              else if(move == K_LEFT)
               x--;
              else if(move == K_RIGHT)
               x++;
           }while(move != K_ESC);
          
          system("PAUSE");
          return 0;
    }
    Btw, look up the function kbhit()...

    EDIT: It looks like I took way too long on that post before red_baron beat me out.

  8. #8
    Banal internet user
    Join Date
    Aug 2002
    Posts
    1,380
    red_baron, TechWin... that will not work in a Win32 console... well, it will compile; But it will not work properly.

    You need to use virtual keys...

    http://cboard.cprogramming.com/showt...threadid=25835

  9. #9
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    I was doing that for Inquirer; for some reason I was thinking he wanted it in console for Dev.

  10. #10
    Banal internet user
    Join Date
    Aug 2002
    Posts
    1,380
    No one answered GreenCherry

  11. #11
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    I'm guessing NULL will indicate an error with getch();
    NULL = 0

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 05-07-2009, 11:31 AM
  2. Win Console program environment variable
    By C3Pnuts in forum C Programming
    Replies: 2
    Last Post: 05-23-2005, 02:08 PM
  3. help with this
    By tyrantil in forum C Programming
    Replies: 18
    Last Post: 01-30-2005, 04:53 PM
  4. Resource ICONs
    By gbaker in forum Windows Programming
    Replies: 4
    Last Post: 12-15-2003, 07:18 AM
  5. memory limits in console (win NT/9X)?
    By dp_goose in forum C++ Programming
    Replies: 1
    Last Post: 10-29-2002, 06:00 AM