Thread: Implenting Function Keys

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    24
    hmmm, thats something like what i would want, but i thought there was a simpler way in getting to implement them, like from a library, but thanks for all the help and new tips i learnt..

  2. #2
    Registered User
    Join Date
    Oct 2008
    Posts
    55
    You can simplify that, but you still need a bunch of defines.
    Code:
    #include <conio.h>
    
    // Name some control-codes
    #define KEY_BEL        7
    #define KEY_BS         8
    #define KEY_TAB        9
    #define KEY_LF        10
    #define KEY_CR        13
    #define KEY_ESC       27
    #define KEY_DEL      127
    
    // If 0 proceeds extended code, add 256
    #define KEY_F1        59 + 256
    #define KEY_F2        60 + 256
    #define KEY_F3        61 + 256
    #define KEY_F4        62 + 256
    #define KEY_F5        63 + 256
    #define KEY_F6        64 + 256
    #define KEY_F7        65 + 256
    #define KEY_F8        66 + 256
    #define KEY_F9        67 + 256
    #define KEY_F10       68 + 256
    
    // If 224 proceeds extended code, add 512
    #define KEY_F11      133 + 512
    #define KEY_F12      134 + 512
    #define KEY_HOME      71 + 512
    #define KEY_UP        72 + 512
    #define KEY_PAGEUP    73 + 512
    #define KEY_LEFT      75 + 512
    #define KEY_RIGHT     77 + 512
    #define KEY_END       79 + 512
    #define KEY_DOWN      80 + 512
    #define KEY_PAGEDOWN  81 + 512
    #define KEY_INSERT    82 + 512
    #define KEY_DELETE    83 + 512
    
    int get_key() {
        int c = getch();
        switch (c) {
          case 0:   return getch() + 256;
          case 224: return getch() + 512;
        }
        return c;
    }
    
    int main() {
        int c;
        while ((c = get_key()) != KEY_ESC) {
            printf( "%d\n", c);
        }
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  4. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  5. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 07:05 PM