Problem 1917. click away
Write a function that clicks on a GUI button.
Description:
Some times one wishes to use Matlab to automate some time consuming repetitive process that requires filling fields or clicking buttons on the screen. Matlab offers a simple way to control the cursor position (e.g. set(0,'pointerlocation',...), but it is not so clear how one would perform mouse or keyboard clicks.
This problem creates a simple message box:
msgbox('Click the OK button','')
which displays the above message and an 'OK' button.
Your function just needs to actually click on the OK button (or use equivalent keyboard shortcuts) to pass this problem. Simple, right?
Solution Stats
Problem Comments
-
11 Comments
and btw, your 'x=msgbox('Ok'); while ishandle(x), disp('hello word!'); pause(2); end' code works (meaning that the loop ends when you click on the 'Ok' button) only because of the "pause" command within the loop. Remove that and it will not work at all. Why? you may ask. Well, pause, exactly like drawnow, will force any pending callbacks to be processed (again, this is detailed in "help drawnow"), so, without it, "ishandle" never notices whether you have clicked on the message box button (because the associated button callback function is not yet been executed), or whether you have even closed the entire message box (because the associated figure CloseRequestFcn callback has not yet been executed). Hope this helps clarify
@Alfonso,did you try clicking on the X or red button to close the dialog window from your example?
@Rafael. Assuming you are referring to the "x=msgbox('Ok'); while ishandle(x), disp('hello world'); end" code, then yes, the figure closes and the loop does NOT break, as one could expected (as the CloseRequestFcn callback, containing the "delete(gcbf)" code, is NOT executed so the loop continues forever). The behavior, of course, is different if you add back the "pause(1)" line within the loop. In that case the figure closes AND the loop ends (since, once the pause command is executed after the figure is closed, that will cause the CloseRequestFcn callback to be executed, which in turn will run the "delete(gcbf)" command, which in turn will make "x" a no-longer-valid graphic handle, which will cause the "ishandle(x)" condition to fail when it gets there). Are you observing the same behavior? (I am on R2020b, perhaps some of this is different in pre-R2014b versions?)
Solution Comments
Show commentsProblem Recent Solvers10
Suggested Problems
-
1937 Solvers
-
2283 Solvers
-
88 Solvers
-
216 Solvers
-
375 Solvers
More from this Author38
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!