Jump to content
  • Advertisement
Sign in to follow this  
PB Baller27

How to Detect the Keyboard W/O cin

This topic is 4342 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

For the past few months I have been writing some small C++ Programs using Visual Studio EE edition and running in the command prompt. Whenever the issue of recieving data from the user occured I would use the std::cin function and assign the input recieved to a variable. cin >> varName; However for cin to work(atleast on my macine) the user has to press enter every time. One program Im writing now invovles quick one character inputs from the user.In the program the user must enter in the letter that is missing in the visible word. So simply how do you write a program that will take input from the user w/o having to press enter everytime?

Share this post


Link to post
Share on other sites
Advertisement
I, for one, would suggest avoiding the C++ standard IO libaries as often as possible... use the C standard libraries instead (stdio.h, stdlib.h, etc).

and most compilers do not require the _ part of the function call. But I do agree, getch() is a good function to use.

Share this post


Link to post
Share on other sites
you could process the raw keyboard input rather then the actual letter, then have your program take action based on that for example:

//CONSOLE

W_termelon

//

//CODE

if(GetAsyncKeyState(Word->Get_letterMissing()))
//solve word
//add a new one
else
//
//your wrong!
//

that is assuming that Get_letterMissing() returns a char.

Where word is an instance of a structure that holds a string to the word and a char to the letter missing.

GetAsync... works on windows only but there are plenty of other ways to grab keyboard input, you could use SDL.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!