Ascii Values - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Ascii Values

avaizavaiz Posts: 6Member
Can anyone tell me what are the ascii values for ALT, Enter and the arrow keys?.

I am trying to make a menu in C for my app.Like i need the file menu to open when i give ALT+F.But i cudnt find the ascii value for ALT,Enter and the arrow keys.

Pls help.

Comments

  • weiccoweicco Posts: 950Member
    : Can anyone tell me what are the ascii values for ALT, Enter and the arrow keys?.
    :
    : I am trying to make a menu in C for my app.Like i need the file menu to open when i give ALT+F.But i cudnt find the ascii value for ALT,Enter and the arrow keys.
    :
    : Pls help.
    :

    ASCII-table can be found here: http://www.asciitable.com/ nice name btw :)

    There is no ASCII value for ATL or arrow keys. If you are using Windows you can use GetAsyncKeyState for checking if key is pressed or not.
  • interrupthandlinterrupthandl Posts: 137Member
    [RED] u can also use scan codes of the keys
    [/RED]



  • avaizavaiz Posts: 6Member
    Thank u both of u.

    But how do i get the scan codes?.
  • shaolin007shaolin007 Posts: 1,018Member
    : Thank u both of u.
    :
    : But how do i get the scan codes?.
    :

    Direct link
    http://www.clipx.net/ng/interrupts_and_ports/ng33ae9.php

    The main page with good programming info

    http://www.clipx.net/norton.php
  • stoberstober Posts: 9,765Member ✭✭✭
    [b][red]This message was edited by stober at 2004-3-9 7:45:36[/red][/b][hr]
    There are, indeed, ascii values for arrow keys. if getchar() returns 0, then someone pressed a special key, such as Function Keys or arrow key. So you need to call getchar() again to get the actual key. The reason for this behavior is that special keys have the same ascii value as normal keys.

    getch() will return 0 if the arrow key on the keypad is pressed, or 224 if the arrow key on the arrow-diamond is pressed

    [code]
    int key;
    BOOL bSpecialKeyHit = FALSE;
    key = getchar();
    if(key == 0)
    {
    // special key hit
    key = getchar();
    bSpecialKeyHit = TRUE;
    }

    [/code]

    Here is a little program that prints the ascii code of any key
    [code]
    #include
    #include

    #define ESC 27
    int main(int argc, char* argv[])
    {

    int key;
    while(1)
    {
    key = getch();
    if(key == ESC)
    break;
    if(key == 0 || key == 224)
    key = -getch();
    printf("%d
    ",key);
    }
    return 0;
    }
    [/code]





  • avaizavaiz Posts: 6Member
    Thank u ppl.I have got my solution.

    Stober, u r lil prog worked like a dream.Its what i wanted!.It is true.The getch() does return all the ascii values, which were not listed in teh the no. of ascii charts i have seen.

    Although u have kept a -ve sign for key=-getch().It returns negative values,which dont work.Only positive 1's work.

    But THANKS A LOT STOBER!.
  • stoberstober Posts: 9,765Member ✭✭✭
    : Thank u ppl.I have got my solution.
    :
    : Stober, u r lil prog worked like a dream.Its what i wanted!.It is true.The getch() does return all the ascii values, which were not listed in teh the no. of ascii charts i have seen.
    :
    : Although u have kept a -ve sign for key=-getch().It returns negative values,which dont work.Only positive 1's work.
    :
    : But THANKS A LOT STOBER!.
    :

    the reason I make them negative is so that you can tell the difference between special keys and regular keys. To use them either use their negative values in switch statement (or other types of comparisons) or convert them back to positive values.
Sign In or Register to comment.