#1
|
|||
|
|||
Another Joystick Question
I'm trying to get Vizard to print the user's yaw and positional information when the joystick trigger is pulled. I've used the sid.get() command to determine that the trigger is button number 1.
However, when I to call on that button using something like this: if data[2] == viz.BUTTON_1: print yaw,pos it returns the following message: AttributeError: 'module' object has no attribute 'BUTTON_1' How does Vizard call on joystick buttons? Thanks! |
#2
|
|||
|
|||
Hi,
To test whether joystick button 1 is down use the following code: Code:
buttons = sid.buttons() if buttons & 1: print 'button 1 is down' |
#3
|
|||
|
|||
Perfect.
I have it set up to give the user's yaw and positional data on the trigger press, but because it is within the joystick control loop, when the trigger is pressed, I get about 10 sets of information. Is there a way to make it so that, no matter how long the trigger is held down, it only prints the information once? Thanks! |
#4
|
|||
|
|||
Hi,
The upcoming version of Vizard will allow you to create callbacks for joystick buttons, but for now you'll have to manually check when a button is first pressed. Here's a simple example: Code:
import viz import sid viz.go() laststate = sid.buttons() def mytimer(num): global laststate state = sid.buttons() if state & 1 and not laststate & 1: print 'button pressed down' laststate = state viz.callback(viz.TIMER_EVENT,mytimer) viz.starttimer(0,0.001,viz.FOREVER) |
|
|