Pressing a certain key!

Hello, I started to use Code::Blocks, and I am a begginer. I wanted to make a kind of a funny game. But i wanted to check if a certain key (like ,,z,,) is pressed. I don't know how, can anybody help me?


I have tried this: key=getch();------but it is just for checking if any key is pressed.
If you already do key = getch();
Assuming key is a char

Can't you use a switch to handle whichever key is pressed?
1
2
3
4
5
6
7
8
9
10
11
12
switch(key)
{
    case 'a':
        //your logic
        break;
    case 'z':
        //your logic
        break;
    default:
        //your logic
        break;
}


EDIT: or if statements, if you don't have too many events to manage.
Last edited on
Topic archived. No new replies allowed.