Question

Usually after getting the input using cin we need to press the Enter key for the value to be stored in the variable. Is there a way to combine both of them? (i.e as soon as I press the ESC it should execute the previous screen operation in the below case without pressing the enter key)

  void func(){
   unsigned char choice;
   cout << "Enter choice: ";
   cin >> choice;
   switch(choice){
      case char(27):
        //performing operation to go to the previous screen
      break;
    }
  }
Était-ce utile?

La solution

No-wait keyboard input depends on the system. A more or less portable solution is to use the Curses library, which is available for both *nix and Windows. However, with a block mode terminal the functionality is just not there to access, so it really depends.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top