:?: How do you make an object, say a rectangle, move in turbo c++, using right and left arrow keys?

I want the object to move when a user presses right or left arrow keys.

Please reply ASAP either here or at my email <<email address snipped>>

Use the nonstandard getch() to handle your keyboard input - but beware, it's not supported on all compilers and the input is non-buffered. That being said, there's no C/C++ standard for asynchronous input as far as I know, so using getch() is your best bet.

Using variables to keep track of the object's location, you can then draw it using Turbo's graphics.h file. There's more information about Turbo graphics here:
http://www.onecore.net/turbo-c-graphics-programming.htm

Hope this helps

hey thanx...but i want to know the exact syntax i need to write to make a rectangle move when a user presses the right or left key. I'm new to Turbo c++ and i would really need all the help i can get.

Thanx a lot

hey thanx...but i want to know the exact syntax i need to write to make a rectangle move when a user presses the right or left key. I'm new to Turbo c++ and i would really need all the help i can get.

Thanx a lot

Start with something a bit more trivial - Learn how to manipulate user input, and how to generate output first. then you'll be one step towards creating a program which combines input/output.

There is no "exact" syntax for doing what you want.. How you accomplish it is entirely up to you, although you need to learn the basics first, then you'll know what options you have available to you.

everybody can help me?????
i want to know how to do the output moving in coding c++....
HELP ME!!!!!!

Comments
Don't post on old threads

you can use function getkey() for getting integer for that key

{
int ch;
if(kbhit())
{
      ch=getkey();
 }

switch(ch)
{
//for right errow key     
case 77:
// type your code here i.e. if you press the right errow key this will happen
//gotoxy(x,y)  function can help you here

//for left errow key     
case 75:
// type your code here 

//for up errow key     
case 72:
// type your code here 

//for down errow key     
case 80:
// type your code here 

}

you can make you own program which will let you know the integer value that getkey() returns for all keys..try it yourself

if u get some error like " function getkey should have a prototype " paste goto.c attached with solution file in bin of your turbo cpp compiler.

hope this will hlp ...

Edited 6 Years Ago by kirit275: n/a

Attachments
#include <dos.h>

/*clears the Screen*/
cls()
{
	union REGS i,o;

	i.h.ah=6;
	i.h.al=0;
	i.h.ch=0;
	i.h.cl=0;
	i.h.dh=24;
	i.h.dl=79;
	i.h.bh=7;
	int86(16,&i,&o);
}

/*Move control to a row column*/
gotorc(int r, int c)
{
	union REGS i,o;
	i.h.ah=2;
	i.h.bh=0;
	i.h.dh=r;
	i.h.dl=c;
	int86(16,&i,&o);
}

/* Getting The Key Scan Code*/
getkey()
{
	union REGS i,o;
	while(!kbhit())
		;
	i.h.ah = 0;
	int86(22,&i,&o);
	return(o.h.ah);
}

/*To hide cursor*/
cursor(int ssl, int esl)
{
	union REGS i,o;
	i.h.ah=1;
	i.h.ch=ssl;
	i.h.cl=esl;
	int86(16,&i,&o);
}
This question has already been answered. Start a new discussion instead.