Kaushik
Kaushik

Reputation: 1339

Combining Keys with ENTER key

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;
    }
  }

Upvotes: 0

Views: 94

Answers (1)

Cheers and hth. - Alf
Cheers and hth. - Alf

Reputation: 145279

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.

Upvotes: 1

Related Questions