Notifications
Clear all

[Closed] Scripting a button press?

Is there a way to script a button pressed event, i.e. have the script press the button? I want to have an action be repeated x amount of times (x = spinner value).

5 Replies

These events can be called by script just as you’d call a function.
Suppose you have a button:

button btnPressMe "Go"

on btnPressMe pressed do ( format "I'm pressed!
" )

You can invoke the pressed event like this:

btnPressMe.pressed()

Simple as that

  • Martijn

magicm you rock thanks. I knew it had to be simple just could not find it in the reference.

On my old 286 if I wanted to use the mouse I had to load the driver myself the driver was called magicms, any relation?

thanks again

is there also a way to simulate a check button, just like how the mybutton.pressed() option works? mycheckbox.checked() doesnt seem to do the trick…

This is because the check button handler expects exactly one argument, which is used to pass the new value in the handler…
It has the form

on myCheckButton changed state do …


 rollout test "Test"
(
	checkbutton myCheckButton "Check"
	on myCheckButton changed state do 
		print ("You passed " +(state as string))
)
createDialog test

Now you can call from the Listener or another script:

test.myCheckButton.changed true
test.myCheckButton.changed false

Note that these calls will not change the actual state of the button, as the handler is the RESULT of the state change when you click with the mouse, NOT the CAUSE.
If you want to force the checked state of the button, you could add the line
myCheckButton.state = state
to the handler:


rollout test "Test"
(
	checkbutton myCheckButton "Check"
	on myCheckButton changed state do 
	(
		myCheckButton.state = state --enforce the state to the button
		print ("You passed " +(state as string)) --print the passed state to verify
	)	
)
createDialog test

thanks bobo! you’re as helpfull as always!
I thought the I have to put something like

test.myCheckButton.changed = true

… so that’s why it wasnt working…