RUSES
Would you like to react to this message? Create an account in a few clicks or log in to continue.
May 2024
MonTueWedThuFriSatSun
  12345
6789101112
13141516171819
20212223242526
2728293031  

Calendar Calendar


Code for arrow keys

Go down

Code for arrow keys Empty Code for arrow keys

Post  lee Mon Feb 27, 2012 9:29 pm

This may be useful for people who are going to have a go at the maze game. It's pretty self explanatory

Source

http://www.gamedev.net/topic/589120-basic-maze-game-c/



Code:
#include <iostream>
#include <conio.h>
/* Key ASCII chars */
#define      KEY_UP      72
#define      KEY_DOWN   80
#define      KEY_LEFT   75
#define      KEY_RIGHT   77

int main()
{
char   input = 0;

/* Keep checking for input untill we press ESC */
while (input != 27) {
   /* Store userinput in our input variable */
   input = getch();

   /* Check for arrow key presses */
   switch (input) {
      case KEY_UP:
         printf("You've pressed KEY UP!\n");
      break;

      case KEY_DOWN:
         printf("You've pressed KEY DOWN!\n");
      break;

      case KEY_LEFT:
         printf("You've pressed KEY LEFT!\n");
      break;

      case KEY_RIGHT:
         printf("You've pressed KEY RIGHT!\n");
      break;
   }
}}
lee
lee

Posts : 22
Join date : 2012-02-23

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum