PDA

View Full Version : How to use arrow keys



ltrain_riders
12-03-2002, 10:58 AM
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.

Julien Cayzac
12-03-2002, 11:16 AM
This has nothing to do with OpenGL.

Julien.

LostInTheWoods
12-03-2002, 12:04 PM
Try using glut. It handles input and works WONDERFULLY with OpenGL.

ltrain_riders
12-03-2002, 12:36 PM
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.

bakery2k
12-03-2002, 12:38 PM
Use glutSpecialFunc.

ltrain_riders
12-03-2002, 01:51 PM
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.

dabeav
12-03-2002, 03:07 PM
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)

ltrain_riders
12-03-2002, 04:40 PM
none of the books i have seem to talk about glSpecialFunc( ), unless I'm overlooking it. Anyone have sources of info on this?

yakuza
12-03-2002, 08:00 PM
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).]

ltrain_riders
12-04-2002, 02:42 PM
how come when i use glutSpecialFunc i lose my alpha blending? Does glutSpecialFunc require me to change anything in glBlendFunc( )

ltrain_riders
12-04-2002, 02:45 PM
Never mind.