kbhit() with enter key? not working

Started by
2 comments, last by Daaark 18 years ago
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.
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)
Ok that seems to be working. Thank you.
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. ;)

This topic is closed to new replies.

Advertisement