:?: 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>>

Recommended Answers

All 6 Replies

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

Member Avatar for iamthwee

No one will write the exact code for you.

So do some reading and write it yourself.

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!!!!!!

commented: Don't post on old threads +0

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 ...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.