![]()  | 
	
| 
	 | 
| 
		 
			 
			#1  
			
			
			
			
			
		 
		
	 | 
|||
		
		
  | 
|||
| 
		
	
		
		
			
			 
				
				unset onkeydown for a key?
			 
			
			
			Hi all 
		
		
		
		
		
		
		
		
	
	Is there a way to unset the onkeydown for a key once you already assigned it an action? Thanks Josh  | 
| 
		 
			 
			#2  
			
			
			
			
			
		 
		
	 | 
|||
		
		
  | 
|||
| 
		
	
		
		
		
		 
			
			You can use: 
		
		
		
		
		
		
		
		
	
	Code: 
	viz.callback(viz.KEYDOWN_EVENT,None) Code: 
	vizact.onkeydown(key, None)  | 
| 
		 
			 
			#3  
			
			
			
			
			
		 
		
	 | 
|||
		
		
  | 
|||
| 
		
	
		
		
		
		 
			
			Thanks so far... 
		
		
		
		
		
		
		
		
	
	The space bar should only be pressed once in my experiment: vizact.onkeydown(' ', play_first_joke) As soon as it's been pressed, it shouldn't invode the play_first_joke method anymore. vizact.onkeydown(' ', None) ...gives the following error: Code: 
	Traceback (most recent call last):
  File "C:\Programme\WorldViz\Vizard30\python\vizact.py", line 3019, in __onkeydown
    self._callGroup(self.__keydownmap[key])
  File "C:\Programme\WorldViz\Vizard30\python\vizact.py", line 2971, in _callGroup
    val = e.call(arg)
  File "C:\Programme\WorldViz\Vizard30\python\vizact.py", line 2794, in _callStatic
    return func(*args,**kwargs)
TypeError: 'NoneType' object is not callable
 | 
| 
		 
			 
			#4  
			
			
			
			
			
		 
		
	 | 
|||
		
		
  | 
|||
| 
		
	
		
		
		
		 
			
			After searching in the documentation I found the following: 
		
		
		
		
		
		
		
		
	
	Code: 
	<vizact>.removeEvent Deletes an EventFunction object <vizact>.removeEvent( eventFunctionObj ) eventFunctionObj Remarks Uses this when you no longer need an EventFunction callback. Return Value None Example eventFunction = vizact.onupdate( 5, doSomething ) ... vizact.removeEvent( eventFunction )  | 
| 
		 
			 
			#5  
			
			
			
			
			
		 
		
	 | 
|||
		
		
  | 
|||
| 
		
	
		
		
		
		 
			
			Thank you. But I don't know how exactly I can use this now... I'm sorry, I'm absolutely new to Python and to the theories that stand behind events in WorldViz...
		 
		
		
		
		
		
		
		
		
	
	 | 
| 
		 
			 
			#6  
			
			
			
			
			
		 
		
	 | 
|||
		
		
  | 
|||
| 
		
	
		
		
		
		 
			
			Whenever you register a function with vizact.onkeydown a reference is made in memory between the keystroke and the function. What you wish to achieve is to break that reference. A way to do that, have your program memorize that reference as a variable and then do some operation on that variable, in this case: removeEvent. 
		
		
		
		
		
		
		
		
			Take for example: Code: 
	def initialiseProgram():
     playJokeEvent = vizact.onkeydown(' ', play_first_joke)
     ... other initialisation
def play_first_joke():
     vizact.removeEvent(playJokeEvent)
     .. do your fancy scene stuff here
Last edited by IGoudt; 03-08-2010 at 05:29 AM.  | 
| 
		 
			 
			#7  
			
			
			
			
			
		 
		
	 | 
|||
		
		
  | 
|||
| 
		
	
		
		
		
		 
			
			Thanks, that helps a lot. :-)
		 
		
		
		
		
		
		
		
		
	
	 | 
![]()  | 
	
	
		
  | 
	
		
  | 
			 
			Similar Threads
		 | 
	||||
| Thread | Thread Starter | Forum | Replies | Last Post | 
| onkeydown list of values | Cheff | Vizard | 2 | 07-02-2008 03:00 AM |