Jump to content
  • Advertisement
Sign in to follow this  
yahn

kbhit() with enter key? not working

This topic is 4494 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

I'm trying to make a loop to build a string while the program is running. When the enter key is hit I want to process the string. Basically I want gets() without blocking. So I'm trying to use kbhit() to do this. This is a windows console aplication. Not win32.
 if (kbhit())
                {
                    str[stri] = getch();
                    cout << str[stri];

                    if (str[stri] == '\n')
                    {
                        //rakClientInterface->RPC("PrintMessage", str, (strlen(str)+1)*8, HIGH_PRIORITY, RELIABLE, 0, false);

                        system("PAUSE");

                        stri = 0;
                        str[0] = '\0';
                    }
                    else
                    {
                        stri++;
                    }
                }

I commented the raknet function and put in system("PAUSE") just to see if it was working, but its not executing system("PAUSE") I don't think. Its not outputing Press any key to continue . . . and when I hit enter it doesn't terminate the program. If you don't know whats wrong and you know of a good website to learn windows thread programming from, could you please drop the link. Thank you for your time.

Share this post


Link to post
Share on other sites
Advertisement
Enter key is ascii code (13), I forget how to convert it. You might just check for 13 as an int value.

if (str[stri] == 13)

Share this post


Link to post
Share on other sites
Quote:
Original post by yahn
Ok that seems to be working. Thank you.
I believe escape is '27'. If you need any other keys just look up their codes in an ascii chart. You should make some defines like

KEY_ENTER
KEY_ESCAPE

so you don't have to remember all these funny numbers. ;)

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!