Sign in to follow this  
Net-Ninja

Console input

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this