7
votes

I'm self studying using the Pearson, Computer Graphics with OpenGL's book.

I'm currently trying to make a simple square move, but before I get ahead of myself I need to be sure I understand what keys are built into Glut.

I'm aware of the following keys:

  • GLUT_KEY_F1, GLUT_KEY_F2, ..., GLUT_KEY_F12 - F1 through F12 keys
  • GLUT_KEY_PAGE_UP, GLUT_KEY_PAGE_DOWN - Page Up and Page Down keys
  • GLUT_KEY_HOME, GLUT_KEY_END - Home and End keys
  • GLUT_KEY_LEFT, GLUT_KEY_RIGHT, GLUT_KEY_UP, GLUT_KEY_DOWN - Arrow keys
  • GLUT_KEY_INSERT - Insert key

I either found them in my book or here on Stackoverflow in another post.

But are there any more? eg, for all keys on a keyboard and mouse?

Thanks.

2

2 Answers

7
votes

glut divides key in keyboard by glutSpecialFunc w/c takes special keys such as F1,F2..., NUMPADS, etc. while glutKeyboardFunc takes all keys that can be represented by a character like the alphabets, numbers, ESC (27 in 'ASCII'), ENTER (32 in 'ASCII'), etc.

in summary, glutKeyboardFunc take char parameters that can be represented without using any '\' (backslash, like '\t', '\n') before any character the rest are handled by glutSpecialFunc

6
votes

the keyboard have two sets of buttons: those that can be represented using ASCII code and those that could not. the ones that can be represented in ASCII returns 1 byte when pressed, the ones that couldn't return two bytes the first of which is NULL

glut abstract this by giving you two set of functions to handle keyboard events: one to handle normal ASCII standard buttons glutKeyboardFunc, the other to handle special two byte buttons glutSpecialFunc

the special function have constants for common keyboard special buttons :

GLUT_KEY_F1:0x0001, GLUT_KEY_F2:0x0002, GLUT_KEY_F3:0x0003, GLUT_KEY_F4:0x0004, GLUT_KEY_F5:0x0005, GLUT_KEY_F6:0x0006, GLUT_KEY_F7:0x0007, GLUT_KEY_F8:0x0008, GLUT_KEY_F9:0x0009, GLUT_KEY_F10:0x000A, GLUT_KEY_F11:0x000B, GLUT_KEY_F12:0x000C, GLUT_KEY_LEFT:0x0064, GLUT_KEY_UP:0x0065, GLUT_KEY_RIGHT:0x0066, GLUT_KEY_DOWN:0x0067, GLUT_KEY_PAGE_UP:0x0068, GLUT_KEY_PAGE_DOWN:0x0069, GLUT_KEY_HOME:0x006A, GLUT_KEY_END:0x006B, GLUT_KEY_INSERT:0x006C, GLUT_KEY_REPEAT_OFF:0x0000, GLUT_KEY_REPEAT_ON:0x0001, GLUT_KEY_REPEAT_DEFAULT:0x0002.

mouse clicks can be handled with the glutMouseFunc and the constants associated with the mouse buttons are: GLUT_LEFT_BUTTON:0x0000, GLUT_MIDDLE_BUTTON:0x0001, GLUT_RIGHT_BUTTON:0x0002

glut can also handle joysticks with the glutJoystickFunc which has the following constants: GLUT_HAS_JOYSTICK:0x0264, GLUT_OWNS_JOYSTICK:0x0265, GLUT_JOYSTICK_BUTTONS:0x0266, GLUT_JOYSTICK_AXES:0x0267, GLUT_JOYSTICK_POLL_RATE:0x0268, GLUT_JOYSTICK_BUTTON_A:0x0001, GLUT_JOYSTICK_BUTTON_B:0x0002, GLUT_JOYSTICK_BUTTON_C:0x0004, GLUT_JOYSTICK_BUTTON_D:0x0008.

if you are using a gaming mouse or a keyboard/joystick with more buttons you can test for what each button returns by outputting the button pressed to the console then directly use this value in your code to know if one of those button is pressed