****(1)*****
#include<stdio.h>
#include<conio.h>
void main()
{
char c;
clrscr();
printf("Press \"Esc\" to exit");
gotoxy(1,10);
c=getch();
while(c!=27)
{
if(c==0)
{
c=getch();
gotoxy(1,10);
clreol();
printf("This key has two ascii values: 0 and %d",c);
}
else
{
gotoxy(1,10);
clreol();
printf("%d",c);
}
c=getch();
}
}
************
*****(2)******
#include<stdio.h>
#include<conio.h>
void main()
{
char c;
int x=1,y=1;
clrscr();
for(y=1;y<17;y++)
{
gotoxy(52,y);
printf("|");
}
gotoxy(1,16);
printf("___________________________________________________/");
gotoxy(1,19);
printf("Press \"Esc\" to exit\n\n");
printf("Use arrow keys to move cursor");
x=1;
y=1;
gotoxy(x,y);
c=getch();
while(c!=27)
{
if(c==0)
{
c=getch();
if(c==77)
{
if(x==51)
{
x=1;
gotoxy(x,y);
}
else
{
x++;
gotoxy(x,y);
}
}
if(c==75)
{
if(x==1)
{
x=51;
gotoxy(x,y);
}
else
{
x--;
gotoxy(x,y);
}
}
if(c==80)
{
if(y==15)
{
y=1;
gotoxy(x,y);
}
else
{
y++;
gotoxy(x,y);
}
}
if(c==72)
{
if(y==1)
{
y=15;
gotoxy(x,y);
}
else
{
y--;
gotoxy(x,y);
}
}
}
else if(c==8)
{
if(x==1)
{
x=51;
gotoxy(x,y);
}
else
{
x--;
gotoxy(x,y);
}
}
else
{
if(x==51)
{
if(y==15)
{
y--;
}
x=x-50;
y++;
gotoxy(x,y);
}
else
{
printf("%c",c);
x++;
}
}
c=getch();
}
}
************
Compiler: Borland's Turbo C++ (Version 3.0)
Special keys(arrow keys,function keys,delete,home,page up,end,....etc) have ascii values but
they have TWO ascii values, and thats why we have to use getch() TWICE
to sense them.
I have NOT used kbhit(), but I got the idea of using getch()
TWICE for special keys from WaltP's post, Thanx WaltP.