Click here to Skip to main content
15,881,938 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionVisual Studio C++ Object Oriented Pin
RobNO17-May-10 12:26
professionalRobNO17-May-10 12:26 
AnswerRe: Visual Studio C++ Object Oriented Pin
chaau17-May-10 13:42
chaau17-May-10 13:42 
GeneralRe: Visual Studio C++ Object Oriented Pin
RobNO18-May-10 11:01
professionalRobNO18-May-10 11:01 
GeneralRe: Visual Studio C++ Object Oriented Pin
RobNO18-May-10 11:25
professionalRobNO18-May-10 11:25 
Questiondefine arrow keys in c Pin
hasani200717-May-10 10:23
hasani200717-May-10 10:23 
AnswerRe: define arrow keys in c Pin
Richard MacCutchan17-May-10 10:25
mveRichard MacCutchan17-May-10 10:25 
AnswerRe: define arrow keys in c Pin
David Crow17-May-10 10:28
David Crow17-May-10 10:28 
AnswerRe: kbhit() Pin
Software_Developer17-May-10 11:03
Software_Developer17-May-10 11:03 
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
QuestionChange the colour in c Pin
hasani200717-May-10 10:18
hasani200717-May-10 10:18 
AnswerRe: Change the colour in c Pin
Richard MacCutchan17-May-10 10:25
mveRichard MacCutchan17-May-10 10:25 
AnswerRe: Change the colour in c Pin
David Crow17-May-10 10:25
David Crow17-May-10 10:25 
AnswerRe: Change the colour in c Pin
CPallini17-May-10 10:29
mveCPallini17-May-10 10:29 
Questionhow to get the walls from input? Pin
hasani200717-May-10 10:14
hasani200717-May-10 10:14 
AnswerRe: With cin? Pin
Software_Developer17-May-10 11:28
Software_Developer17-May-10 11:28 
QuestionChanging edit box font size Pin
pjdriverdude17-May-10 7:35
pjdriverdude17-May-10 7:35 
AnswerRe: Changing edit box font size Pin
David Crow17-May-10 8:13
David Crow17-May-10 8:13 
GeneralRe: Changing edit box font size Pin
pjdriverdude17-May-10 9:39
pjdriverdude17-May-10 9:39 
Questionhow to know the control? Pin
chikach17-May-10 7:12
chikach17-May-10 7:12 
AnswerRe: how to know the control? Pin
David Crow17-May-10 7:15
David Crow17-May-10 7:15 
GeneralRe: how to know the control? Pin
chikach18-May-10 4:54
chikach18-May-10 4:54 
QuestionPNG image in Dialog Pin
tamila_tamila17-May-10 7:07
tamila_tamila17-May-10 7:07 
AnswerRe: PNG image in Dialog Pin
jeron117-May-10 7:14
jeron117-May-10 7:14 
GeneralRe: PNG image in Dialog Pin
tamila_tamila18-May-10 1:00
tamila_tamila18-May-10 1:00 
QuestionVisual studio debugger yellow arrow cursor/owner draw control Pin
ForNow17-May-10 6:56
ForNow17-May-10 6:56 
AnswerRe: Visual studio debugger yellow arrow cursor/owner draw control Pin
Chris Losinger17-May-10 9:31
professionalChris Losinger17-May-10 9:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.