# Demo of reading a whole string from the keyboard, by saving each # individual key as it's pressed 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() savedString = '' def keyboard(key, x, y): global savedString, animating if key == chr(27): sys.exit(0) elif key == chr(13): print savedString, 'was typed' if savedString == 'anim': animating = not animating savedString = '' else: savedString += key startTime = time.time() def idle(): global frame, size, startTime, animating 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) glutIdleFunc(idle) glutMainLoop()