C/C++ Program to respond to commands in C++

  • Thread starter Thread starter JamesU
  • Start date Start date
  • Tags Tags
    C++ Program
AI Thread Summary
To enable a C++ program to respond to user commands such as arrow key presses or mouse clicks, event handling subroutines are essential. This involves capturing specific keycodes and implementing logic to react accordingly. For instance, using libraries like SDL can simplify the process of managing events. A basic example involves checking for arrow key inputs and executing code within curly braces to change an object's position. For those familiar with Microsoft Developer Studio, utilizing the Microsoft Foundation Class Library can streamline event handling, allowing for quick creation of Windows applications and integration of event handlers. Tutorials like "Scribble" are recommended for beginners to learn Windows programming fundamentals.
JamesU
Gold Member
Messages
821
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:
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...
Back
Top