I'm trying to catch the Esc key but I don't know how to do that
So here is my code describing what I want to do
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <iostream>
#include<stdio.h>
usingnamespace std;
int main()
{
cout<<"enter character or press Esc "<<endl;
switch(cin.get())
{
case'1': //call to function 1
break;
case'2'://call to function 2
break;
case'Escape key pressed':call to function 3//I don't know how to do this
break;
default:cout<<"Error"<<endl;
}
}
First, cin.get() won't get you anywhere with this. You can pull it off by using getch() (part of conio.h) and testing its ASCII value accordingly. Take note that this isn't standard.
1 2 3 4 5 6
key = getch();
switch(key) {
//...
case 27: function() // ascii char code for ESC
}