Check key Backspace
How can I check the Backspace key? I tried this:
char ch = getchar();
while (ch != 'x')
{
ch = ge开发者_运维百科tchar();
if (ch == 0x08)
{
printf("BS");
}
}
but it does not work, any suggestions?
Thx
If stdin is line-buffered then you'll never see the keypresses, only the final result. The exact method for disabling line-buffering can be found in other answers here.
If you use the <conio.h>
there is a getch()
method which can catch that key, but it does not echo it IIRC, it's been a long time since faffing around with those... the neat thing about using that function, it is portable in the sense that under Unix and curses, there's an exact same function that does the same thing...
精彩评论