Creating a subroutine to intercept keyboard events with GLUT application programmer interface:
int main (int argc, char *argv[])
{
glutInit (&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (X_RESOLUTION, Y_RESOLUTION);
glutInitWindowPosition (0,0);
glutCreateWindow ("Mouse keyboard click demo");
glutDisplayFunc (display);
glutReshapeFunc (reshape);
glutMouseFunc (mouse);
glutKeyboardFunc (keyboard);
glutSpecialFunc (arrow_keys);
glutMainLoop ();
}
Creating a subroutine to intercept keyboard events with GLUT application programmer interface:
int main (int argc, char *argv[])
{
glutInit (&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (X_RESOLUTION, Y_RESOLUTION);
glutInitWindowPosition (0,0);
glutCreateWindow ("Mouse keyboard click demo");
glutDisplayFunc (display);
glutReshapeFunc (reshape);
glutMouseFunc (mouse);
glutKeyboardFunc (keyboard);
glutSpecialFunc (arrow_keys);
glutMainLoop ();
}
Creating a subroutine to intercept keyboard events with GLUT application programmer interface:
int main (int argc, char *argv[])
{
glutInit (&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (X_RESOLUTION, Y_RESOLUTION);
glutInitWindowPosition (0,0);
glutCreateWindow ("Mouse keyboard click demo");
glutDisplayFunc (display);
glutReshapeFunc (reshape);
glutMouseFunc (mouse);
glutKeyboardFunc (keyboard);
glutSpecialFunc (arrow_keys);
glutMainLoop ();
}
void mouse (int mouse_button, int state, int x, int y)
{
if (mouse_button == GLUT_LEFT_BUTTON)
{
if (state == GLUT_UP)
{
}
if (state == GLUT_DOWN)
{
}
}
if (mouse_button == GLUT_MIDDLE_BUTTON)
{
if (state == GLUT_UP)
{
}
if (state == GLUT_DOWN)
{
}
}
if (mouse_button == GLUT_RIGHT_BUTTON)
{
if (state == GLUT_UP)
{
}
if (state == GLUT_DOWN)
{
}
}
}
void keyboard (unsigned char key, int x, int y)
{
switch (key)
{
case 27: // escape key
break;
default:
break;
}
}
void arrow_keys (int key, int x, int y)
{
switch (key)
{
case GLUT_KEY_UP:
break;
case GLUT_KEY_DOWN:
break;
case GLUT_KEY_LEFT:
break;
case GLUT_KEY_RIGHT:
break;
default:
break;
}
}
Next I’ll demonstrate a program that captures mouse clicks and keyboard input.
Fall 2016, CS-116A:
Lectures:
Assignments:
Handouts:
Programs: