WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 06-04-2010, 05:32 AM
4711 4711 is offline
Member
 
Join Date: Jan 2010
Posts: 15
Simple Joystick Question

Hi all,

I have a question concerning the joystick buttons which is probably rather easy to be answered: How can I make my script to wait for the user to press one of the two buttons of a connected joystick.

My guess was:
Code:
import viz
import vizjoy
import viztask

viz.go()

joystick = vizjoy.add()

def WaitForButtonPress():
	yield viztask.waitButtonDown(None)
	print "Done."
	viz.quit()
	
viztask.schedule( WaitForButtonPress() )
It works fine if one replaces the "Button" by "Key" in the yield-expression, so I would have expected it to run for the joystick buttons as well. However, it does not, so what works?
Reply With Quote
  #2  
Old 06-04-2010, 12:50 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
The viztask.waitButtonDown command waits for a GUI button object to be pressed. To wait for a joystick button press in your task function you can create a custom condition. The task function in the following example waits for either buttons 1 or 2 to be pressed before it continues:
Code:
import viz
import viztask
import vizjoy

viz.go()
joystick = vizjoy.add()

def buttonTask():
	
	d = viz.Data()
	waitButton1 = waitJoyButtonDown(joystick,1)
	waitButton2 = waitJoyButtonDown(joystick,2)
	
	yield viztask.waitAny([waitButton1,waitButton2],d)
	
	if d.condition is waitButton1:
		print 'button 1 was pressed'
	else:
		print 'button 2 was pressed'
		
	viz.quit()	

class waitJoyButtonDown( viztask.Condition ):
    def __init__( self, joy, button ):
        self._joy = joy
        self._button = button
   
    def update( self ):
        return self._joy.isButtonDown(self._button)

viztask.schedule( buttonTask() )
Reply With Quote
  #3  
Old 06-07-2010, 07:06 AM
4711 4711 is offline
Member
 
Join Date: Jan 2010
Posts: 15
Hi Jeff,

thanks for the clarification on the viztask.waitButtonDown command and also for your code which works fine for me!
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
simple VRPN question mjabon Precision Position Tracker (PPT) 2 08-25-2009 10:12 PM
simple question? Boombay Vizard 1 07-06-2009 10:51 AM
Facetracking and Immersion Joystick Vygreif Vizard 1 01-25-2006 10:56 AM
Another Joystick Question Plasma Vizard 3 02-03-2004 11:16 AM
Basic Joystick Navigation Question Plasma Vizard 2 01-29-2004 07:08 PM


All times are GMT -7. The time now is 03:20 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC