Home > Enterprise >  Why does checking the ASCII code of "Del" button returns 83?
Why does checking the ASCII code of "Del" button returns 83?

Time:11-14

Pressing Del is dealt with as it is an extended key, it returns ASCII code -32 then 83, while pressing Ctrl back returns the expected 127: the actual ASCII of Del button.

Do you know any explanation for this?

char x;
x = getch();
if(x == -32 || x == 0){
x = getch();
    printf("The key you pressed is an Extended Key, with ASCII code: %d\n", x);
}else{
    printf("The key you pressed is a Normal Key, with ASCII code: %d\n", x);
}

CodePudding user response:

The Del key on a standard keyboard does not generate a "Delete" ASCII code: code 127 in the ASCII table isn't meant to do what the Del key does on a computer, it was designed for electric typewriters.

The Del key is a "special key" in a similar vein as the arrow keys, so when you submit it to getch() it will read out is scan code.

  • Related