DirectButton command execution - getButtonState(index)?

Hi all,

Let me see if I can explain this briefly…

From experiementing I have discovered that the command function in DirectButton is executed FOLLOWING release of the mouse button. Makes sense (click!)… but …

I would like to use DirectButton to execute a function WHILE the button is held down.

Pseudo-code:

mybutton=DirectButton(stuff… command=myfunction … stuff)

def myfunction()
do-stuff

So,
you click on mybutton and hold the button down and myfunction is called AFTER releasing the mousebutton.

Is there a way to execute myfunction while the button is held down?

Possibly related question: syntax for using getButtonState(index). The API manual says the index is the index of the button. How do you know the index of a particular button? Any syntax examples would be very very appreciated!!!

Try:

button.bind(B1PRESS, myPressFunc)
button.bind(B1RELEASE, myReleaseFunc)

This will call myPressFunc() when the button-1 mouse button is pressed on your button, and call myReleaseFunc when it is released–so you can do (and undo) whatever you like in those two functions.

I’m not sure what you’re referring to with getButtonState(). Each button has a state, which is BUTTON_READY_STATE, BUTTON_DEPRESSED_STATE, BUTTON_ROLLOVER_STATE, or BUTTON_INACTIVE_STATE (0, 1, 2, or 3), but I don’t know of any method called getButtonState(). Maybe you’re thinking of the button.stateNodePath list?

David