help about reading from console screen in c++

Thread Starter

moslem

Joined Dec 16, 2009
20
Hello ever one,
i've aquestion about reading from console screeen i've a search engine project and i want when i start to enter the required word to search the console begins to display suggestions like google in the attached photo my problem now how can i make the main sense the letter before pressing enter to display the suggestions before the user press enter to search.
my mean in a nother way:
in main when i identify for ex
string i;
cin>>i;
the variable i will set to the value after entering it from console screen and press enter i want to sense every letter before pressing enter to be able to display suggestions to the user.
thanks alot.
 

Attachments

Last edited:

BMorse

Joined Sep 26, 2009
2,675
well since you did not mention what OS, I will assume windows....

Try including the windows.h file and use the GetKeyState() function

Like this: (This example scans through all keys and returns which one is pressed, but it also eats up a lot of cycles and does not work well with cin, but this is just one example of available functions from the win32 API)

Rich (BB code):
int getKey(){
    int buttonpressed = 0;
    while (!buttonpressed){
        for (int i = 0; i < 255; i++){
            if (GetKeyState(i) < 0){buttonpressed = i;}
        }
    }
    while (GetKeyState(buttonpressed) < 0){;}
    return buttonpressed;
}
B. Morse
 

Thread Starter

moslem

Joined Dec 16, 2009
20
@B. Morse
i heard about method or command called console.readkey() method or function is that way you explained above if not what's this method.
thanks.
 

Thread Starter

moslem

Joined Dec 16, 2009
20
@B. Morse
can you please explain this function to me i can't understand it clearly ana explain how can i use it.
thanks in advanced.
 
Top