| MATLAB Function Reference | Search  Help Desk |
| waitforbuttonpress | Examples See Also |
Wait for key or mouse button press
Syntax
k = waitforbuttonpress
Description
k = waitforbuttonpress
blocks the caller's execution stream until the function detects that the user has pressed a mouse button or a key while the figure window is active. The function returns
0 if it detects a mouse button press
1 if it detects a key press
CurrentCharacter, SelectionType, and CurrentPoint properties.
If a WindowButtonDownFcn is defined for the figure, its callback is executed before waitforbuttonpress returns a value.
Example
These statements display text in the Command Window when the user either clicks a mouse button or types a key in the figure window:w = waitforbuttonpress;
if w == 0
disp('Button press')
else
disp('Key press')
end
See Also
dragrect, figure, gcf, ginput, rbbox, waitfor