detecting keypress

This is a discussion on detecting keypress within the C++ Programming forums, part of the General Programming Boards category; hi guys, i've searched the web for this and thhis board but i cant find it. i need to know ...

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    88

    detecting keypress

    hi guys, i've searched the web for this and thhis board but i cant find it. i need to know how to detect a keypress. for example if the right arrow/left arrow/up/down is pressed i need to know. im trying to make a pacman console dealie. this is obviously ssytem dependant so i have either windows with msvc 6.0 (that means no conio.h answers) or linux g++ (but i dont really want X window libraries) thx for responses.

  2. #2
    Registered User Gnoober's Avatar
    Join Date
    Oct 2002
    Posts
    40
    Getch() may be what you want. You can just say something like:

    char ch=getch();

    but I don't know about arrow keys. Maybe someone with more experience could help you out.
    - Grady (:

  3. #3
    Casual Visitor
    Join Date
    Oct 2001
    Posts
    350
    msvc 6 has conio.h and does have getch() though it's not standard. Well at least my copy of vc6 does.

    Code:
    unsigned key1, key2;
    
    do
    {
        key1 = getch();
        switch(key1)
        {
            case 0: key2 = getch();
                         switch(key2)
                         {
                              case 72, 75, 77, 80 arrow keys
                         };
         };
    }while(key1 != 27);
    There is probably a windoze alternative, but I don't know it.
    I haven't used a compiler in ages, so please be gentle as I try to reacclimate myself. :P

  4. #4
    Registered User
    Join Date
    Jan 2003
    Posts
    88
    tehehe i had conio and getch all along, i just remembered calling it when i didnt know what i was doing. thx!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. (MFC, Visual C++) Keypress Detection in a dialog...
    By guitarist809 in forum Windows Programming
    Replies: 4
    Last Post: 08-31-2008, 01:13 PM
  2. Detecting empty file situation.
    By xIcyx in forum C Programming
    Replies: 9
    Last Post: 06-18-2008, 10:37 PM
  3. Detecting keypress
    By dandago in forum C Programming
    Replies: 4
    Last Post: 06-10-2007, 09:34 AM
  4. How do I NOT wait for a keypress?
    By misplaced in forum C++ Programming
    Replies: 9
    Last Post: 04-13-2005, 04:10 PM
  5. Detecting a KeyPress
    By fuh in forum C++ Programming
    Replies: 12
    Last Post: 06-16-2003, 06:44 PM

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