View Single Post
  #1  
Old 01-04-2010, 12:43 PM
starbug starbug is offline
Member
 
Join Date: Dec 2009
Posts: 5
return variable from keypress function

I am relatively new to Vizard and Python, could you point me to some solutions for the following problem?

I want to change a variable in function MyTask() according to a keypress - input in function onKeydown() (if-switch). I just haven't found a way to return a variable from onKeydown. I tried the viz.callback function, and to give it enough time, I am trying to combine it with the viztask.waitKeyDown() function, but I just cannot produce an output form onKeydown.

Here the respective code:

def onKeydown(key):
if key == 'y':
incr = 5
elif key == 'n':
incr = -5
return incr

def MyTask():

while True:
yield viztask.waitKeyDown(('y','n'))
a = 10
b = onKeydown(viz.callback(viz.KEYDOWN_EVENT, onKeydown))
a = a + b
print a

viztask.schedule( MyTask() )

Any suggestions? thanks a lot!
Reply With Quote