Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. define arrow keys in c

define arrow keys in c

Scheduled Pinned Locked Moved C / C++ / MFC
learning
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hasani2007
    wrote on last edited by
    #1

    Hello I am a beginner in c(win32 console). I want to define arrow keys in c in order to a character travels up, down, left and right. PLEASE EXPLAIN AS COMPLETE AS POSSIBLE... thanks all

    L D S 3 Replies Last reply
    0
    • H hasani2007

      Hello I am a beginner in c(win32 console). I want to define arrow keys in c in order to a character travels up, down, left and right. PLEASE EXPLAIN AS COMPLETE AS POSSIBLE... thanks all

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      See my answer to your other question.

      It's time for a new signature.

      1 Reply Last reply
      0
      • H hasani2007

        Hello I am a beginner in c(win32 console). I want to define arrow keys in c in order to a character travels up, down, left and right. PLEASE EXPLAIN AS COMPLETE AS POSSIBLE... thanks all

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        hasani2007 wrote:

        I want to define arrow keys in c in order to a character travels up, down, left and right.

        I could easily give you the numbers, but it would be of more benefit to you to create a little test program that uses getch() to get those keys (and others) and print their values to the screen. You can then use those values in your program.

        "One man's wage rise is another man's price increase." - Harold Wilson

        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

        "Man who follows car will be exhausted." - Confucius

        1 Reply Last reply
        0
        • H hasani2007

          Hello I am a beginner in c(win32 console). I want to define arrow keys in c in order to a character travels up, down, left and right. PLEASE EXPLAIN AS COMPLETE AS POSSIBLE... thanks all

          S Offline
          S Offline
          Software_Developer
          wrote on last edited by
          #4

          How to define arrow keys in c. 1. Define keys. 2. Put kbhit() in a function. 3. Create a loop. 4. Thats it. Step 1.

          #define UP 72
          #define DOWN 80
          #define LEFT 75
          #define RIGHT 77

          Step 2.

          void pumpKeyboardMessages(void)
          {
          if (kbhit())
          {
          ch=getch();
          }
          }

          Step 3.

          while (ch!=ESCAPE)
          {
          pumpKeyboardMessages( );

          // Do Other Stuff

          }

          Step 4. Here's an example of usage:

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

          #define UP 72
          #define DOWN 80
          #define LEFT 75
          #define RIGHT 77
          #define SPACE 32
          #define ENTER 13
          #define ESCAPE 27
          #define TAB 9
          #define INSERT 82
          #define F1 59

          void pumpKeyboardMessages(void)
          {
          if (kbhit())
          {
          ch=getch();

          switch (ch)
          {
              case LEFT:
          		//  Do Stuff
          	break;
          
          	case RIGHT:
          		//  Do Stuff
          	break;
          
          	case UP:
          		//  Do Stuff
          	break;
          
          	case DOWN:
          		//  Do Stuff
          	break;
          
          	case ENTER:
          	break;
          
          	case SPACE:
          	break;
          
          	case F1:
           
          	break;
          
          	case TAB:
          		 
          	break;
          }
          

          }

          }

          int main(void)
          {
          getReady();
          initGame();
          bas=time(0)+1;
          while (ch!=ESCAPE)
          {
          pumpKeyboardMessages( );

          	// Do Other Stuff
          
          } 
          return 0;
          

          }

          Also check out my articles about console applications. How to create a Win32 Console Mode breakout brick game How to create a Win32 Console Mode breakout brick game How to create an object oriented Win32 Console application How to create an object oriented Win32 Console application How to handle mouse events in a Win32 Console in C++ with Random Joke Generator How to handle mouse events in a Win32 Console in C++ with Random Joke Generator

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups