Program to respond to commands in C++

  • C/C++
  • Thread starter JamesU
  • Start date
  • Tags
    C++ Program
In summary: SDL:That's a bit complicated. I would recommend looking into using something like SDL. It makes creating games much easier.
  • #1
JamesU
Gold Member
815
3
I want to know how I can get my program to respond to commands in C++. for instance, when someone presses the up, down, or side arrows; or when somebody clicks something.
 
Technology news on Phys.org
  • #2
yomamma said:
I want to know how I can get my program to respond to commands in C++. for instance, when someone presses the up, down, or side arrows; or when somebody clicks something.

That's fairly complicated. You have to have some sort of event handling subroutines to respond to various keycodes(as I understand it. I've never needed such a thing, and so have never bothered to learn how). Try googling for event handling in C++ or some such thing.
 
  • #4
well, I'm trying to learn how to move something (like a basic game) but how would I make the computer respond to the arrow key. woul I use something like?:

arrokey

cin>>arrowkey>>\n

if (arrowkey==uparrow)
{
}

My nect question is about what I would put inbetween the curly braces. how could I get something to change position?

and I don't really want to download any pregrams, just write it out.
 
  • #5
Your thinking on too simple of a level.

You need to do something like this:

http://www.libsdl.org/cgi/docwiki.cgi/Event_20Examples

This example is actual very simple. If you wanted to be more sophiscated you would have your input handled by another thread.
 
Last edited by a moderator:
  • #6
yomamma said:
I want to know how I can get my program to respond to commands in C++. for instance, when someone presses the up, down, or side arrows; or when somebody clicks something.

In the past, I've used quite a bit the Microsoft Developer Studio Visual C++ and the Microsoft Foundation Class Library: Can create a working windows program in a few key strokes then just add to it. Simple matter then to add event handlers to respond to keystrokes. Know about "Scribble"? That's the tutorial to get you going on Windows programming. Of course I suppose you need to already know quite a bit about Windows programming to do the tutorial. Also, Developer Studio has a great debugger.
 
Last edited:

1. What is a "Program to respond to commands" in C++?

A "Program to respond to commands" in C++ is a computer program written in the C++ programming language that is designed to take in commands from a user and execute specific actions based on those commands.

2. How does a program to respond to commands in C++ work?

A program to respond to commands in C++ typically works by first taking in user input using the "cin" function. The program then uses conditional statements, such as "if" and "else" statements, to check the input and determine what action to take based on the command given.

3. What are some common uses for a program to respond to commands in C++?

A program to respond to commands in C++ is commonly used in various applications such as chatbots, virtual assistants, and command-line interfaces. It can also be used in games, automation tasks, and other interactive programs.

4. Can a program to respond to commands in C++ be customized?

Yes, a program to respond to commands in C++ can be customized to fit specific needs and requirements. This can be done by adding more commands and actions, modifying the existing code, or using different libraries and functions.

5. Are there any important considerations when writing a program to respond to commands in C++?

When writing a program to respond to commands in C++, it is important to carefully handle user input to avoid errors or unexpected behavior. It is also crucial to properly document the code and use efficient programming techniques to ensure the program runs smoothly and efficiently.

Similar threads

  • Programming and Computer Science
Replies
14
Views
2K
  • Programming and Computer Science
Replies
1
Views
259
  • Programming and Computer Science
Replies
7
Views
469
  • Programming and Computer Science
Replies
12
Views
9K
  • Programming and Computer Science
Replies
1
Views
682
  • Programming and Computer Science
Replies
10
Views
2K
Replies
3
Views
330
  • Programming and Computer Science
Replies
2
Views
308
  • Programming and Computer Science
Replies
4
Views
3K
Replies
6
Views
649
Back
Top