'How do i make the program accept the second input before the first one while keeping the delay?

If i press A then B quickly, i would like the program to display Case B before Case A while still keeping the delay on Case A but no matter how i do it after pressing A then B the program still waits 2 seconds for Case A to finish. What should i do? Also i apologize for my poor english skills.

        if (_kbhit()){
        
        
        switch (getch()){
            case 'a':
                Sleep(2000);
                cout << "AAAAA";
                break;
                
            case 'b':
                cout << "BBBBB";
                break;
            
        }

}
c++


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source