Sign in to follow this  

kbhit() with enter key? not working

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

This topic is 4273 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.

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