Console input

Started by
3 comments, last by nobodynews 14 years, 2 months ago
Hi, I am wondering how to get lowlevel platform independent information about keyboard input in console mode. The programming language is C++ under visual studios. What I'm basically trying to do is se if any key is being pressed asynchronously. Can't find a solution with cin.

Video Game Programmer.
5 years in industry.

Advertisement
Have you tried the methods defined in conio.h? I am not sure if they are platform independent.
With Visual Studio you should be able to use conio.h.

kbhit() will return true if a key was hit and getch() will tell you the character hit. But as nGamer said, that's not platform independent.

Since you are using Visual Studio, you can also include windows.h and use GetAsyncKeyState

Thread about that one here:
http://www.gamedev.net/community/forums/topic.asp?topic_id=338405

For platform independent information about keyboard input you'll likely want to look at 3rd party libraries such as nCurses though I'm not sure how widely supported that one is.
Conio is windows only it seems.
kbhit() does the charm, hoped there would be a more platform independent alternative though.

Video Game Programmer.
5 years in industry.

Quote:Original post by Net-Ninja
Conio is windows only it seems.
kbhit() does the charm, hoped there would be a more platform independent alternative though.


The problem with conio is that it is a non-standard header that was implemented by many compilers in the past but has since begun to fall out of favor, probably due to its non-standardness. If it was 3rd party it probably would be more commonly used these days.

You could also try the SDL library for your input needs as SDL is platform independant. I'm not sure if you would consider that low level enough, but basically you would use this.

C++: A Dialog | C++0x Features: Part1 (lambdas, auto, static_assert) , Part 2 (rvalue references) , Part 3 (decltype) | Write Games | Fix Your Timestep!

This topic is closed to new replies.

Advertisement