Thread: What are the key values?

  1. #1
    Unregistered
    Guest

    Post What are the key values?

    This will probably sound incredibly ignorant to most of you, but I can't seem to find the values of different keys on the keyboard. As an example, I've included the following:

    ...

    if(kbhit())
    {
    key = getch();
    }

    if(key == 27)
    {
    gamestat = GAMEQUIT;
    }

    ...

    and so on. This snippet is part of a DOS console game I wrote quite awhile ago. I know that 27 is the value of the "Esc" key, and this segment tells the program to quit. But I don't know the values of others keys like the arrows. If you know anything that I don't, please reply to my post.
    Thanks Everyone!!!

  2. #2
    Unregistered
    Guest
    You could modify this to find out the values of your keys?


    include <stdio.h>

    main()
    {
    int i;

    i = 65;
    do {
    printf("The numeric value of %c is %d.\n", i, i);
    i++;
    } while (i<72);
    return 0;
    }

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    412

    Re: What are the key values?

    Originally posted by Unregistered
    This will probably sound incredibly ignorant to most of you, but I can't seem to find the values of different keys on the keyboard. As an example, I've included the following:

    ...

    if(kbhit())
    {
    key = getch();
    }

    if(key == 27)
    {
    gamestat = GAMEQUIT;
    }

    ...

    and so on. This snippet is part of a DOS console game I wrote quite awhile ago. I know that 27 is the value of the "Esc" key, and this segment tells the program to quit. But I don't know the values of others keys like the arrows. If you know anything that I don't, please reply to my post.
    Thanks Everyone!!!

    Do a google search for an ASCII key table -- the values between 32 and 127 are listed, and those will be the key codes.

    However, arrow keys, function keys (F1, F2, etc), and those are not single characters -- rather, they send 2 characters -- a zero as the first character, and a second char which specifies the key which is hit.

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    411
    you can just use the letter with single quotes


    case 'a':
    do something
    break;
    case 'A':
    do something else
    break;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. STL Container, key with two values?
    By leeor_net in forum C++ Programming
    Replies: 4
    Last Post: 03-12-2009, 04:21 AM
  2. Function to check memory left from malloc and free?
    By Lechx in forum C Programming
    Replies: 4
    Last Post: 04-24-2006, 05:45 AM
  3. Reading problem
    By Tubs in forum C Programming
    Replies: 6
    Last Post: 03-24-2006, 01:30 AM
  4. BCB Key press problem
    By Death_Wraith in forum Game Programming
    Replies: 0
    Last Post: 05-30-2004, 03:13 PM
  5. key problem
    By madsmile in forum Game Programming
    Replies: 20
    Last Post: 06-05-2002, 10:57 PM