putting condition on input

This is a discussion on putting condition on input within the C Programming forums, part of the General Programming Boards category; Hello all. I been workin on my pgm for the past 2-3 days, it's up to 418 lines of code ...

  1. #1

    putting condition on input

    Hello all. I been workin on my pgm for the past 2-3 days, it's up to 418 lines of code ( small i know ).

    I would like to know how to preform an action immediately when escape is pressed. The most simpilest way yet versitle.


    if ( /* code for detecting escape */ )

    printf("um..."); /* immediate action */

    I just spent 30min reading through tuts and links and things, can't really find it. Must've overlooked somewhere.

  2. #2
    small example

    int c;

    c = getchar();

    // now press escape and then enter
    // printf("%d\n",c); would give 27, we use this figure

    case 27: // escape was pressed
    // action to do

    // case 3: // control C was pressed
    // break;


    Hope this small example can help you.

  3. #3


    Doesn't seem to work.

    First off /* This is a comment in code */

    Im looking to have something done right when the key is pressed, not having to press enter. If i press the correct key, it's to late, i dont have to press enter to activate my choice.

    Can somebody point me to some good tutorials ( either detailed or several locations ) dealing with reading key presses from the keyboard and taking immediate action along with using loops.

    That'd be nice. It's better then bugging you with tons of questions. I've looked, just haven't found much.

  4. #4
    Registered User
    Join Date
    Sep 2001
    This isn't standard, but I'm guessing it's still pretty generic...

    #include <keys.h>
    #include <pc.h>
    main ()
     int key;
     for (;;)
      key = getkey();
      switch (key)
       case K_Esc: printf ("Esc!\n"); break;
       case 'q': case 'Q': exit (0); break;
       default: break;
    At least that'll put you kn the right track maybe.

  5. #5
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    This worked for me. Adapte it how you wish.
    #define ESC 0x1B
    char ch=0;
    printf("Done Sir Done");
    There you go.


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  2. For loop problems, input please.
    By xIcyx in forum C Programming
    Replies: 2
    Last Post: 04-22-2007, 03:54 AM
  3. I would love some input on my BST tree.
    By StevenGarcia in forum C++ Programming
    Replies: 4
    Last Post: 01-15-2007, 12:22 AM
  4. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 03:42 PM
  5. need help with some input
    By blindleaf in forum C Programming
    Replies: 2
    Last Post: 03-16-2003, 12:50 PM

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