Link to home
Start Free TrialLog in
Avatar of konna432
konna432

asked on

Need codes for getting the input of the "arrow" on the keyboard in c++

Hi guys..

how are you doing?
i'm not doing too good here..

anyway i think my question title has sum up the whole thing.. hehe :P

i would like to know the codes for getting the input from the keyboard when a user preses the arrow keys.
ie: up, down. left. right

how would that represent in term of c++? i have been trying to code this for the past fews days.. and so far i have not found or understand how to do it.. hahahahahhaa.. (-_-")

thank you ever so much guys... :D
Avatar of Axter
Axter
Flag of United States of America image

What type of project do you have, and what platform?
Also what is your compiler?
Avatar of konna432
konna432

ASKER

the project is for the user to press either left of right key to go forward and backward..

i am using Linux.. well.. using C++ for the programme

i would like to read the key as a char array.. this is because i am using cin.getline()
any idea?
Here's some example code for Win32 console application:

enum { LEFT_ARROW=75, UP_ARROW=72, RIGHT_ARROW=77, DOWN_ARROW=80};

 int ch = getch();
  if(ch == 0) {
      ch = getch();      // retrieve the second byte
        switch (ch) {
            case UP_ARROW:
                // do some code
                break;
            case DOWN_ARROW:
                // do some code;
                break;
            case LEFT_ARROW:
                // do some code;
                break;
            case F1:
                // do some code;
                break;
            case F2:
                // do some code;
                break;
             // ... etc ...
        }                        
    }

ASKER CERTIFIED SOLUTION
Avatar of Axter
Axter
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
For more info, see following link:
http:Q_20337616.html
Thank you Axter (^_^)

you are the man.. :D i'll try to complie it now.. see if it work
else i'll get back to you and ask you some more questions about it (^_^)
hey Axter..

mind telling me what

#define VK    27
#define VK2   91

are for?
My Linux knowledge is limited.
27 is the escape key in DOS/Windows.
I believe in Linux 27 signals that spacial character is to follow.

I'm assuming that VK2 is a certain sub set of the extended/special characters.
thank you for helping me out ;)
>>thank you for helping me out ;)

Why the C grade? :-(