Program to respond to commands in C++

  • Context: C/C++ 
  • Thread starter Thread starter JamesU
  • Start date Start date
  • Tags Tags
    C++ Program
Click For Summary

Discussion Overview

The discussion revolves around how to implement command responses in C++ programs, particularly focusing on handling keyboard inputs such as arrow keys and mouse clicks. The scope includes event handling, programming techniques, and potential libraries for game development.

Discussion Character

  • Exploratory
  • Technical explanation
  • Homework-related

Main Points Raised

  • One participant expresses a desire to understand how to make a C++ program respond to keyboard and mouse commands.
  • Another participant suggests that event handling is complex and recommends researching event handling in C++.
  • A third participant provides a link to the SDL (Simple DirectMedia Layer) library, which is often used for handling events in games.
  • A participant shares a specific example of attempting to read arrow key inputs and questions how to change an object's position based on those inputs.
  • Another participant critiques the simplicity of the previous approach and suggests looking at more sophisticated examples, including handling input in a separate thread.
  • A participant mentions their experience with Microsoft Developer Studio and the Microsoft Foundation Class Library, indicating that it simplifies event handling for Windows applications.

Areas of Agreement / Disagreement

Participants do not reach a consensus on a single method for handling commands in C++. Multiple approaches and tools are suggested, indicating a variety of opinions and techniques available.

Contextual Notes

Some participants reference specific libraries and frameworks, which may require prior knowledge of certain programming concepts or environments. The discussion does not resolve the best approach for handling events in C++.

JamesU
Gold Member
Messages
828
Reaction score
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
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.
 
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[/color])
{
}

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

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
Replies
14
Views
4K
Replies
86
Views
4K
  • · Replies 12 ·
Replies
12
Views
12K
Replies
7
Views
4K
  • · Replies 25 ·
Replies
25
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
Replies
69
Views
11K
Replies
2
Views
2K