input in realtime.

Started by
18 comments, last by Puneet Chandhok 9 years, 5 months ago
help me guys...
what is the easiest way to take input from keyboard, in realtime , in c++ ??
CEO of the future gaming industry
Advertisement

1.) It would be helpful to know what operating system you want to use.

2.) What is "realtime" in your case? You know, realtime means fast enough to not cause noticeable artifacts, but that depends also on the environment where the input should be handled.

i'm creating a game in c++ .
i need to take input from user....while the display function still continue its work...

but actually in my program...
compiler is waiting for user input in every frame.

i'm using win xp sp 3.
CEO of the future gaming industry

i'm creating a game in c++ .
i need to take input from user....while the display function still continue its work...

but actually in my program...
compiler is waiting for user input in every frame.

i'm using win xp sp 3.

http://msdn.microsoft.com/en-us/library/windows/desktop/ms646267(v=vs.85).aspx

[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

A few things:

The compiler runs only once, to create the executable file, it is not running when you run the game (compile time and run time are completelly different things), so the compiler can't be waiting for user input. I guess you mean the app itself, you'll get more help using the correct words.

Most APIs like SDL and SMFL have 2 methods for handling input, event driven and state drive.

Event driven means the API stores events in one place, and when you checks for events (keyUp, keyDown, etc) they are removed. This way you don't wait for input, you just process everything that happened since your last check and move on, if there's nothing to process, nothing is blocked.

State driven means that you check for the state of the input when you need to, and do stuff if the state is the one you need.

The aproach of "wait until there's input" is mostly used in console applications where you stop while waiting for something from "standard input" or a network, which is actually a text input, it's not really meant to be used to detect key presses.

Anyway, if you can't use events or check the state of a particular key, you can run separated threads, one for rendering and one for input handling and game state update, but you need to take care of concurrency.

thank you.. diego for correcting me...
and thank u .. simon.. your link helped a lot
CEO of the future gaming industry

Just a hint: Designing a Robust Input Handling System for Games by ApochPiQ

My personal opinion: don't waste time on manual input handling concurrency, just let the Window Procedure do the job or use DirectInput if you wanna run it own thread.

"Recursion is the first step towards madness." - "Skegg?ld, Skálm?ld, Skildir ro Klofnir!"
Direct3D 12 quick reference: https://github.com/alessiot89/D3D12QuickRef/

You will never be able to get real-time input from any Windows operating system, as these are not real-time operating systems (RTOS). Windows lets you get keyboard presses and depresses as events (and you can also get the internal timer value for when this happened) as window messages sent to a window, or to get the state of the keys (pressed or not) at any time. It's up to you to use all of these in such a way that the user thinks everything is happening in real-time.

Also, console programs are a bit different, as they put the key events into an input buffer that you can read from, and in this case, I don't think you can get the timer value for when the event happened...

Since you haven't specified what sort of program you are writing (console or GUI), the question still remains too broad for us to give you a straight answer.

You will never be able to get real-time input from any Windows operating system, as these are not real-time operating systems (RTOS). Windows lets you get keyboard presses and depresses as events (and you can also get the internal timer value for when this happened) as window messages sent to a window, or to get the state of the keys (pressed or not) at any time. It's up to you to use all of these in such a way that the user thinks everything is happening in real-time.

Also, console programs are a bit different, as they put the key events into an input buffer that you can read from, and in this case, I don't think you can get the timer value for when the event happened...

Since you haven't specified what sort of program you are writing (console or GUI), the question still remains too broad for us to give you a straight answer.

Every time I see a "realtime" thread, one moronic wannabe just shows up trying to make the OP feel as stupid as possible.

It is incredibly obvious that the OP is a beginner, and doesn't need actual realtime input.

Edit:

Lol at the downvotes. I'm speaking the damn truth. It's okay to mention that realtime isn't the correct term.

However: "omg but realtime is not possible on Windows" etc... that is the kind of attitude that I am talking about here.

Why not just casually mention it and move on to actually answering the question?

Don't just treat the topic as if it actually is something else than what the OP intended.


Every time I see a "realtime" thread, one moronic wannabe just shows up trying to make the OP feel as stupid as possible.

It is incredibly obvious that the OP is a beginner, and doesn't need actual realtime input.

Sorry... I wasn't trying to make anyone feel stupid.

This topic is closed to new replies.

Advertisement