Test for certain key entry's


If I am using getche to capture a single character input or may begin using getch instead, and then it is stored in a variable to work with, but before doing much else, would like to test it for presence of such things as
a ctrl key input, or backspace, or Enter and so forth. What would be a good way to test that variable for this and how to determine what the character code would be to be tested for etc..

Thanks.

I think that some of this is handled for you, but if you are just reading it into a char variable, you could do something like this.

1
2
3
4
5
6
7
char a;
//getch stuff
if( a >= 'A' && a <= 'z'){
  //Is alpha
}else if( a >= '0' && a <= '9'){
 //Is a digit
}...


And you could use this to ensure that you only allow the values you wanted to accept through.
Topic archived. No new replies allowed.