Hey guys i have a question which i have been looking for the answer to for quite a while, i have seen many questions alike but none solved my problem.
So i have a function that grabs the players name using get line that goes like this.
std::cout << "Enter your name"<< std::endl;
std::string input;
std::getline(std::cin, input);
and afterwards I have a function that has a menu which tells the user he can press a series of keys to move on to other parts of the menu.
while(true)
{
//menu one
if(GetAsyncKeyState(VK_CONTROL))
{
Menu_3();
}
//here is the problem
if(GetAsyncKeyState(VK_SHIFT) && GetAsyncKeyState(0x53)) //0X53 = S
{
Menu_4();
}
}
My problem is that if i use a name with a capital letter(created with SHIFT) and an ‘s’ also Menu_4() gets called automatically after i enter the name, example name “Shawn”. if i only have a name like this “shawn”(without using shift) then that “s” seems to get stored in the cin buffer and all that is required to move on is press “shift” to get into Menu_4();
Basically the input is getting carried over from the getline name request and its screwing up my GetAsyncKeyState() calls.
Thanks for your help.
I think you misunderstood the behavior of GetAsyncKeyState
see GetAsyncKeyState
Probably you want to check the current state not if the key was pressed from last call.