From: Kadir H. <kha...@ya...> - 2009-09-27 19:05:40
|
Hello All, I am trying to write a little routine, which will enable intreacting with the program while it is looping. It is basically intended for debugging, butit may also be useful for changing some attributes (and hence the logic) in flight. I am using the keyboard events to break-into the loop. I am using the "@" character as a special character, then, once detected I input my command from the shell (with preceeding/following quote signs). It works OK for the first time. But, after the first one, "scene.kb.keys" does not sense the input key. Most probably, with the input() command I am breaking some stack, etc., so that visual can not detect the keyboard input. You can find the sample code below. Any ideas will be appreciated. Thanks, Kadir ====================================== from visual import * bb = box() while 1: if scene.kb.keys: # event waiting to be processed? s = scene.kb.getkey() # get keyboard info print "s ", s # this is the key pressed if s == "@": # see if it is the break character "@" df = input("Enter Command: ") # If True, then wait for command input print df # This is the command entered try: # it may be an invalid command, be prepared print eval(df) # execute the command and print the result except: pass # if invalid command do nothing s = "" # reset the input key print scene.kb.keys # check if there are any other keyboard events bb.rotate(axis=(0,1,0), angle=0.01) # set something going on in the loop rate(25) |