# Demo of recording keyboard state, for multi-key commands # Holding 'a' and 'b' keys together animates the teapot 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() keystate = { 'a':False, 'b':False } def keyboard(key, x, y): global keystate if key == chr(27): sys.exit(0) else: keystate[key] = True def keyboardUp(key, x, y): global keystate keystate[key] = False startTime = time.time() def idle(): global frame, size, startTime, keystate frame = frame + 1 if keystate['a'] and keystate['b']: 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) glutIgnoreKeyRepeat(1) glutIdleFunc(idle) glutMainLoop()