Hi every body
i need a code of program that makes a number puzzle.
the puzzle has 16 pieces,that move with arrow keys.
this is my project!
plzzzzzzzzzzz help me!:sad:

There is no standard way of doing that in C language. But one method is to use non-standard conio.h function getche(). If your compiler supports that function then you can use this program to find out what values your keyboard sends for any key on the keyboard, including arrow keys. Arrow and function keys are a little different than all the other keys because they produce two values, not one. So if the first time getche() return either 0 or 224 then there will be another value which will be the actual key. Special keys (function keys and arrow keys) have the same scan code as normal keys so you will want to change the key to tell your program that it is a special key. For example, pressing the right arrow on the arrow pad will produce the sequence 224 and 77. When the program gets 224 then it has to call getche() again to get the value 77. Since the value 77 duplicates another key you will want to do something with it that will identify it as a special key. Some programmers will just add 255 to it, making it 332. I usually just make it negative, or -77.

#include <stdio.h>
#include <conio.h>

int main (void)
{
    int c;
    while( (c = getche()) >= 0)
    {
        printf("%d\n", c);
    }
}

Experiment with the above program hitting various keys so that you can see what happens.

Next I would write a small function that returns the key

#define LEFT_ARROW    77
#define RIGHT_ARROW  75
#define UP_ARROW        72
#define DOWN_ARROW   80
int getkey()
{
    int c;
    c = getche();
    if( c == 0 || c == 224 )
    {
          c = getche();
          c *= -1; // make it negative
    }
    return c;
}

int main()
{
    int c;
    while( (c = getkey()) != 0)
     {
         switch(c)
         {
             case RIGHT_ARROW:
                 printf("Right Arrow Hit\n";
                 break;
             // etc etc for the other keys
        }
  }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.