# Demo of keyboard-up function, and special-key functions import sys, math, time from OpenGL.GLUT import * from OpenGL.GL import * from OpenGL.GLU import * frame = 0 size = 0.5 animating = False def draw(): global frame, size glClear(GL_COLOR_BUFFER_BIT) glutWireTeapot(size) glFlush() def keyboard(key, x, y): global animating if key == chr(27): sys.exit(0) elif key == 'a': animating = True def keyboardUp(key, x, y): global animating if key == 'a': animating = False def specialKey(key, x, y): if key == GLUT_KEY_FORWARD: print 'move forward' def specialKeyUp(key, x, y): if key == GLUT_KEY_FORWARD: print 'stop moving forward' startTime = time.time() def idle(): global frame, size, startTime frame = frame + 1 if animating: size = math.sin(time.time()) glutPostRedisplay() glutInit([]) glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB) glutInitWindowSize(200, 200) glutInitWindowPosition(0,0) glutCreateWindow(sys.argv[0]) glutDisplayFunc(draw) glutKeyboardFunc(keyboard) glutKeyboardUpFunc(keyboardUp) glutSpecialFunc(specialKey) glutSpecialUpFunc(specialKeyUp) glutIgnoreKeyRepeat(1) glutIdleFunc(idle) glutMainLoop()