Reputation: 139
I have "glutKeyboardFunc (keyboard);" in my main function, How I can detect when user press 'comma' or full-stop. I want to move (strafe) to your left in the XZ plane a distance when comma is pressed. and move to right in the XZ plane when full-stop is pressed. The current code does not response.
if(key==GLUT_KEY_UP)
{
eyez = eyez + RUN_SPEED;
}
else if(key==GLUT_KEY_DOWN)
{
eyez = eyez - RUN_SPEED;
}
else if(key==',')
{
eyex = eyex - RUN_SPEED;
}
else if(key=='.')
{
eyex = eyex - RUN_SPEED;
}
Upvotes: 1
Views: 811
Reputation:
What you need here, dear fellow UoM student enrolled in COMP27112, is the ASCII codes for comma and dot.
That is 44 and 46 respectively.
case 44:
// Comma
break;
case 46:
// Dot
break;
Upvotes: 1
Reputation: 52082
The glutKeyboardFunc()
callback is only for ASCII-type keys. I'm surprised you are getting arrow key events from it.
Create a glutSpecialFunc()
callback for non-ASCII keys.
Upvotes: 1