Getting ASCII codes

This is a discussion on Getting ASCII codes within the C Programming forums, part of the General Programming Boards category; I wrote a small program that tries to get the ASCII key codes for every key we press until we ...

  1. #1
    Registered User moonwalker's Avatar
    Join Date
    Jul 2002
    Posts
    282

    Question Getting ASCII codes

    I wrote a small program that
    tries to get the ASCII key codes for
    every key we press until we press Esc.

    It is working fine all the time except when
    we press certain keys (example: arrow keys)
    It is printing an extra zero before printing
    the actual values (which are correct)

    why am i getting this zero ?

    here's the code:

    PHP Code:
    #include <stdio.h>
    #include <conio.h>

    main()
    {
        
    char c;
        
        
    printf("KEY\tCODE\n");

        while ((
    getch()) != 27)
        {
            
    printf("%3c\t%4d\n"c, (int)c);
            
    fflush(stdin);
        }


  2. #2
    ggs
    ggs is offline
    C > C++ duders ggs's Avatar
    Join Date
    Aug 2001
    Posts
    435
    certain keys are 'extended' and return a 0 followed by a keyboard scan code. it's normal.
    .sect signature

  3. #3
    Registered User moonwalker's Avatar
    Join Date
    Jul 2002
    Posts
    282

    how can we get key codes for...

    how can we get key codes for shift, control, etc ?

  4. #4
    ggs
    ggs is offline
    C > C++ duders ggs's Avatar
    Join Date
    Aug 2001
    Posts
    435
    err, i don't know if you can using ordinary input functions. i do know that shift and ctrl are scan code modifiers that set extra bits in the scan code, but somebody else will have to tell you how to find that out in c. alternately, you could try google.com
    .sect signature

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question about ASCII codes
    By rwmarsh in forum C++ Programming
    Replies: 4
    Last Post: 04-17-2006, 11:49 AM
  2. ASCII Codes
    By X PaYnE X in forum Windows Programming
    Replies: 1
    Last Post: 12-31-2003, 01:37 PM
  3. ASCII Codes
    By drdroid in forum C++ Programming
    Replies: 11
    Last Post: 05-02-2002, 05:00 PM
  4. ascii codes!!
    By condorx in forum C Programming
    Replies: 23
    Last Post: 04-30-2002, 09:10 PM
  5. converting scan codes to ascii codes
    By stupid_mutt in forum C Programming
    Replies: 11
    Last Post: 01-25-2002, 04:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21