define arrow keys in c
-
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
-
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
-
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
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
-
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
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 77Step 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 59void 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