Keyboard Codes

This is a discussion on Keyboard Codes within the Game Programming forums, part of the General Programming Boards category; I'm fairly new to GLUT programming, and this is a slight problem I had. GLUT calls my keyboard function when ...

  1. #1
    User
    Join Date
    Jan 2006
    Location
    Canada
    Posts
    498

    Keyboard Codes

    I'm fairly new to GLUT programming, and this is a slight problem I had. GLUT calls my keyboard function when a key is pressed. Here is what it looks like:

    Code:
    void keyboard(unsigned char key, int x, int y) {
    
    switch (key) {
    
        case 'd':
        // do something here
        break;
    
        default:
        break;
    }
    
    }
    Okay, that works as far as I'm concerned. But obviously I need keyboard codes to read keys such as ESC, and ARROWKEYS. Where do I find the codes for these?

  2. #2
    Yah. Morgul's Avatar
    Join Date
    Feb 2005
    Posts
    109
    VK_ESCAPE
    VK_UP
    VK_DOWN
    VK_LEFT
    VK_RIGHT
    etc
    Sic vis pacum para bellum. If you want peace, prepare for war.

  3. #3
    User
    Join Date
    Jan 2006
    Location
    Canada
    Posts
    498
    The compiler doesn't recognize it. Probably because I'm on a Mac. Or do I need a certain header?

  4. #4
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,812
    Those key codes are for windows.
    You could just output the keycode char to see what it is when those keys are pressed. I don't know much about glut so I can't give you an exact.
    Here you go
    http://www.opengl.org/resources/libr...00000000000000
    Last edited by prog-bman; 02-20-2006 at 09:16 PM.
    Woop?

  5. #5
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    open up glut.h and look

    GLUT_KEY_LEFT
    GLUT_KEYF1
    etc..

    http://www.cs.mcgill.ca/~bcheun1/glut.h

  6. #6
    User
    Join Date
    Jan 2006
    Location
    Canada
    Posts
    498
    Thanks.... should have thought of it myself.

  7. #7
    User
    Join Date
    Jan 2006
    Location
    Canada
    Posts
    498
    It didn't work. I opened up the debugger, and the function never gets called when an arrow key or other "special" key gets pressed. It only gets called when a key like 'W' get pressed. This is the line I'm using to get my keyboard input:

    Code:
    // (main function)
    glutKeyboardFunc(keyboard);
    .
    .
    .
    glutMainLoop();
    Last edited by joeprogrammer; 02-21-2006 at 07:45 PM.

  8. #8
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,812
    Got to put glutSpecialFunc
    Code:
    void SpecialKeys(int key, int x, int y)
    {
        case GLUT_KEY_UP:
        //do something
    }
    glutSpecialFunc(SpecialKeys);
    //so on so forth
    Woop?

  9. #9
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    Have a look here for some commonly used glut callbacks
    http://jeff.bagu.org/downloads/glut/EmptyGlut.cpp

  10. #10
    User
    Join Date
    Jan 2006
    Location
    Canada
    Posts
    498
    OK good. Thanks for your help. I'm just working through the tutorials on NeHe and they don't cover every thing about game programming, so it's good to have a nice forum like this one

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Keyboard port using other that a keyboard
    By antoinelac in forum C++ Programming
    Replies: 4
    Last Post: 06-12-2008, 03:46 PM
  2. Virtual keys
    By Arkanos in forum Windows Programming
    Replies: 4
    Last Post: 12-12-2005, 10:00 AM
  3. Game Design Topic #2 - Keyboard or Mouse?
    By TechWins in forum Game Programming
    Replies: 4
    Last Post: 10-08-2002, 04:34 PM
  4. ...keyboard codes...
    By Sebastiani in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 04-05-2002, 04:23 PM
  5. : Difference between message queue and keyboard buffer...
    By Unregistered in forum Windows Programming
    Replies: 0
    Last Post: 02-21-2002, 03:47 PM

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