How to use arrow keys

I want to move an object I made by using the arrow keys. I created a switch statement inside a keyboard function that reads the input, but how can I tell if the arrow keys are being pressed? I tried using:
case VK_LEFT:
case VK_UP:
case VK_DOWN:
case VK_RIGHT:
but that doesn’t seem to work.

This has nothing to do with OpenGL.

Julien.

Try using glut. It handles input and works WONDERFULLY with OpenGL.

i have:
glutKeyboardFunc ( keyboard );
and then my keyboard function looks like this:
void keyboard ( unsigned char key, int x, int y )
{
switch ( key ) {
case 27: /* Escape key */
exit ( 0 );
break;
case ‘q’:
exit( 0 );
break;
case ‘f’:
glutFullScreen ( );
break;
case ‘w’:
glutReshapeWindow ( 800, 600 );
break;
case VK_LEFT:
yrot -= 0.1;
glRotatef( yrot, 0.0, 1.0, 0.0 );
break;
case VK_RIGHT:
yrot += 0.1;
glRotatef( yrot, 0.0, 1.0, 0.0 );
break;
case VK_UP:
exit( 0 );
default:
break;
}
}
the characters work but the arrow keys do not.

Use glutSpecialFunc.

i have:
glutKeyboardFunc ( keyboard );
and then my keyboard function looks like this:
void keyboard ( unsigned char key, int x, int y )
{
switch ( key ) {
case 27: /* Escape key */
exit ( 0 );
break;
case ‘q’:
exit( 0 );
break;
case ‘f’:
glutFullScreen ( );
break;
case ‘w’:
glutReshapeWindow ( 800, 600 );
break;
case VK_LEFT:
yrot -= 0.1;
glRotatef( yrot, 0.0, 1.0, 0.0 );
break;
case VK_RIGHT:
yrot += 0.1;
glRotatef( yrot, 0.0, 1.0, 0.0 );
break;
case VK_UP:
exit( 0 );
default:
break;
}
}
the characters work but the arrow keys do not.

The arrow keys are special keys in GLUT, they need the specialkey function, look it up, the keys are different then VK_, that is microsofts version. (I think)

none of the books i have seem to talk about glSpecialFunc( ), unless I’m overlooking it. Anyone have sources of info on this?

This definitely doesn’t belong in the OpenGL forums, much less the advanced forum. I’d suggest visiting the forums at Gamedev.net with these type questions in the future.

Here’s the code you’re looking for:

void SpecialKeys(int key, int x, int y)
{
switch (key)
{
case GLUT_KEY_LEFT:
doSomething();
break;
case GLUT_KEY_RIGHT:
doSomething();
break;
case GLUT_KEY_UP:
doSomething();
break;
case GLUT_KEY_DOWN:
doSomething();
break;
}
}

With this in your main:

glutSpecialFunc(SpecialKeys);

I’d also suggest learning to use a search engine, I’m sure a google search on “glutSpecialFunc” would have turned up inumerable results.

[This message has been edited by yakuza (edited 12-03-2002).]

how come when i use glutSpecialFunc i lose my alpha blending? Does glutSpecialFunc require me to change anything in glBlendFunc( )

Never mind.