-
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?
-
VK_ESCAPE
VK_UP
VK_DOWN
VK_LEFT
VK_RIGHT
etc
-
The compiler doesn't recognize it. Probably because I'm on a Mac. Or do I need a certain header?
-
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
-
open up glut.h and look ;)
GLUT_KEY_LEFT
GLUT_KEYF1
etc..
http://www.cs.mcgill.ca/~bcheun1/glut.h
-
Thanks.... should have thought of it myself.
-
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();
-
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
-
Have a look here for some commonly used glut callbacks
http://jeff.bagu.org/downloads/glut/EmptyGlut.cpp
-
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 :)