Thread: How to get scan code of ESC key?

  1. #1
    Registered User
    Join Date
    Sep 2014
    Posts
    8

    How to get scan code of ESC key?

    i wrote the following code :

    Code:
    #include<stdio.h>#include<conio.h>
    #include<stdlib.h>
    
    
    int a[][4] = {15,9,10,25,6,2,4,7,32,19,42,8,21,17,18,0};
    void boxes();
    void display();
    
    
    void main()
    {
        int ch,r=3,c=3,t;
        clrscr();
    
    
        gotoxy(20,7);    printf("USE ARROW KEYS TO PLAY THIS GAME");
        gotoxy(20,8);    printf("--------------------------------");
        boxes(),
        display();
    
    
        while(1)
        {
            ch=getch();
            if(ch==0 || ch==224)
            {
                switch(getch())
                {
                        case 72:
                                if(r!=0)
                                {
                                    t=a[r][c];
                                    a[r][c]=a[r-1][c];
                                    a[r-1][c]=t;
                                    display();    r--;
                                }
                                else
                                    printf("\a");
                                break;
    
    
                        case 80:
                                if(r!=3)
                                {
                                    t=a[r][c];
                                    a[r][c]=a[r+1][c];
                                    a[r+1][c]=t;
                                    display();    r++;
                                }
                                else
                                    printf("\a");
                                break;
    
    
                        case 75:
                                if(c!=0)
                                {
                                    t=a[r][c];
                                    a[r][c]=a[r][c-1];
                                    a[r][c-1]=t;
                                    display();    c--;
                                }
                                else
                                    printf("\a");
                                break;
    
    
                        case 77:
                                if(c!=3)
                                {
                                    t=a[r][c];
                                    a[r][c]=a[r][c+1];
                                    a[r][c+1]=t;
                                    display();    c++;
                                }
                                else
                                    printf("\a");
                                break;
    
    
                        case 1:
                                exit(1);
    
    
                        default:
                            printf("\a");
                }
            }
        }
        getch();
    }
    void boxes()
    {
        int c,r;
        gotoxy(20,10);    printf("%c",218);
        gotoxy(32,10);    printf("%c",191);
        gotoxy(20,18);    printf("%c",192);
        gotoxy(32,18);    printf("%c",217);
    
    
        for(c=21;c<32;c++)
        {
            gotoxy(c,10);    printf("%c",196);
            gotoxy(c,12);    printf("%c",196);
            gotoxy(c,14);    printf("%c",196);
            gotoxy(c,16);    printf("%c",196);
            gotoxy(c,18);    printf("%c",196);
        }
    
    
        for(r=11;r<18;r+=2)
        {
            gotoxy(20,r);    printf("%c",179);
            gotoxy(23,r);    printf("%c",179);
            gotoxy(26,r);    printf("%c",179);
            gotoxy(29,r);    printf("%c",179);
            gotoxy(32,r);    printf("%c",179);
        }
    
    
        for(c=23;c<30;c+=3)
        {
            gotoxy(c,10);    printf("%c",194);
            gotoxy(c,18);    printf("%c",193);
        }
    
    
        for(r=12;r<17;r+=2)
        {
            gotoxy(20,r);    printf("%c",195);
            gotoxy(32,r);    printf("%c",180);
        }
    
    
        for(c=23;c<30;c+=3)
        {
            gotoxy(c,12);    printf("%c",197);
            gotoxy(c,14);    printf("%c",197);
            gotoxy(c,16);    printf("%c",197);
        }
    }
    void display()
    {
        int i,j,r=11,c=21;
    
    
        for(i=0;i<4;i++)
        {
            for(j=0;j<4;j++)
            {
                gotoxy(c,r);
                if(a[i][j]!=0)
                    printf("%d",a[i][j]);
                else
                    printf("  ");
                c+=3;
            }
            r+=2;    c=21;
        }
    
    }


    not able to esc when i press esc key.how to get rid of this.

  2. #2

  3. #3
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    Where do you test for ESC?
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  4. #4
    Registered User laughing_man's Avatar
    Join Date
    Jun 2009
    Location
    Bombay, India
    Posts
    26
    I think keycode for ESC is ASCII 27.

  5. #5
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Quote Originally Posted by laughing_man View Post
    I think keycode for ESC is ASCII 27.
    The ASCII 27 control has nothing to do with the escape key on the keyboard.

    Quote Originally Posted by wikipedia
    Even though many control characters are rarely used, the concept of sending device-control information intermixed with printable characters is so useful that device makers found a way to send hundreds of device instructions. Specifically, they used ASCII code 27 (escape), followed by a series of characters called a "control sequence" or "escape sequence". The mechanism was invented by Bob Bemer, the father of ASCII.
    (source)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Please wait for IDE scan?
    By george_1988 in forum Tech Board
    Replies: 2
    Last Post: 10-12-2008, 12:10 PM
  2. Scan Textfiles
    By Coding in forum C++ Programming
    Replies: 19
    Last Post: 02-07-2008, 06:27 AM
  3. Available COM ports scan
    By Buzzer in forum C++ Programming
    Replies: 5
    Last Post: 05-12-2006, 07:28 AM
  4. while (scan != 'y' or 'n) or if(scan != 'y' or 'n)
    By Blizzarddog in forum C++ Programming
    Replies: 6
    Last Post: 10-23-2002, 01:16 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM

Tags for this Thread