keyboard help

I am trying to make a RPG game and in it I want to have an object move,  and I want the object to move with the keyboard. So if I want it to move up, I hit up on the keyboard and the object will move up. I need some detailed example how to do this.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

lee5i3Author Commented:
Edited text of question
This depends upon whether you are writing a dos-based or windows
based game. In dos you can use getchar() to trap the value of the
key. In windows, you can trap WM_CHAR messages which tell you
what key or keys have been pressed. Windows will have #defines
for keys like up-arrow and down-arrow.. i.e. VK_UPARROW, etc...

  For example,

  In Dos...
    int iKeyPressed;  /* The code of the key pressed */
    /* Keep checking for a pressed key  
    while ( ( iKeyPressed = getchar() != 'q' ) {
      printf( "Key %c was pressed and it's code is %d\n",
              iKeyPressed );

    That will help you figure out the values to chek for.. i.e.
up-arrow = 65 or whatever.
   So you let your application do whatever it needs to do.
Then when it catches a keystroke, you pass that off to a handling

lee5i3Author Commented:
the code you did, didnt work, when it ran it didnt give correct keyboard code, can you check on it. I wont grade you yet.
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

lee5i3Author Commented:
you see, i already know how to get the code from it, but i dont understand how to make it move.
lee5i3Author Commented:

Here is a function that I built once it moves objects :

/* Move a character.
   keypressed - the key the user pressed 0 for function to read the key.
   CX, CY - pointers to x&y of the character.
   x0,y0,Mx,My - Borders
   step - movement step
   IxS, IyS - Image X&Y size

   The function checks to which direction the char should move by checking the
   keypressed, and then checks if it will be within the bordes before moving it.
   In graphics mode, enter a non0 imagesize.
   It checks whether the X,Y are Smaller/Greater than the image X/Y size + the step
   so that part of the image won't be outside the borders.

/*Move*/ void move(char keypressed, int *CX, int *CY , int x0, int y0, int Mx, int My, int step, int IxS, int IyS)
/*Move*/ {
/*Move*/   if (keypressed == 0) keypressed = getch();
/*Move*/   if (keypressed == 0) keypressed = getch();
/*Move*/     switch(keypressed)
/*Move*/     {
/*Move*/       case 80 : if (*CY <= My-step-IyS) *CY += step; break;
/*Move*/       case 72 : if (*CY >= y0+step) *CY -= step; break;
/*Move*/       case 75 : if (*CX >= x0+step) *CX -= step; break;
/*Move*/       case 77 : if (*CX <= Mx-step-IxS) *CX += step; break;
/*Move*/       case 71 : if (*CX >= x0+step) *CX -= step; if (*CY >= step+y0) *CY -= step; break;
/*Move*/       case 73 : if (*CX <= Mx-step-IxS) *CX += step; if (*CY >= step+y0) *CY -= step; break;
/*Move*/       case 79 : if (*CX >= x0+step) *CX -= step; if (*CY <= My-step-IyS) *CY += step; break;
/*Move*/       case 81 : if (*CX <= Mx-step-IxS) *CX += step; if (*CY <= My-step-IyS) *CY += step; break;
/*Move*/       case 27 : exit(1); break;
/*Move*/     }
/*Move*/ }

You should give the function the parameters it requires and it automatically changes the X/Y given to it, and checks that they are within the borders that gave it.
Here is a small program part demonstrating its use:

/* program for a face to move in ansi mode. Not letting it out of the screen */

#include ..... /*include everything that is needed */

void main (void)
  int x,y; /* Position of the face */
  int ox, oy /* Old position of the face */

  clrscr(); x = ox = 39; y = oy = 13;  
    gotoxy(x,y); putchar(1); /* put the face in its position */
    move(0, &x, &y, 1, 1, 79, 24, 1, 0, 0); /* change the face         X/Y position according to the key the user presses. */
    gotoxy(ox,oy); putchar(' '); /* delete the face from the old         position. */
    ox = x; oy = y;/*The new position is now the old position*/
    /* the next time the loop runs it will put the face in the        modified X/Y after the old position was deleted. */  

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.