How do I simulate a click button in matlab

How do I simulate a button click in matlab?

Plainly excluding the callback function does not work as it uses the gcbo command in its callback and I cannot change the excecuting function. Also, I would not want gcbo shadow for obvious reasons.

In case it matters, I'm looking for a solution that works on matlab R2012a.

+3


source to share


2 answers


you can try calling the class java.awt.Robot for example.

robot = java.awt.Robot;
pause(2) % wait some time
robot.keyPress (java.awt.event.KeyEvent.VK_ENTER); % press "enter" key
robot.keyRelease (java.awt.event.KeyEvent.VK_ENTER); %  release "enter" key

      



read more about GUI automation using Robot here ...

I'm not sure if this will work on Matlab R2012a, but it will be in later versions.

+7


source


gcbo

contains only a button handle. If you have (or can find / find) a button handle, simply call the callback function with the button handle as the first argument and an empty variable as the second argument.

something similar to:

button_callback( buttonHandle , [] ) ;

      

The callback will have no meaning between gcbo

or the button handle and will work exactly the same.


If you don't have a handle to the button in the first place, you can try to find it with findobj

:

buttonHandle  = findobj(gcf,'Style','PushButton','String','The Button Text')

      



Depending on how the GUI was created / defined, then the visibility of the visibility may not be immediately obvious, in which case you can search deeper findall

:

buttonHandle   = findall(gcf,'Style','PushButton','String','The Button Text')

      

or maybe the handle was well kept in the guidata structure:

handles = guidata(gcf) ;

      

and find the framework your button can be for.

Note: In the last three examples above, make sure that the GUI drawing that contains the button has focus before you call, gcf

or better yet, replace gcf

the handle with an actual number.

+1


source







All Articles