Products & Services Solutions Academia Support User Community Company

Learn more about MATLAB   

waitforbuttonpress - Wait for key press or mouse-button click

Syntax

k = waitforbuttonpress

Description

k = waitforbuttonpress blocks the caller's execution stream until the function detects that the user has clicked a mouse button or pressed a key while the figure window is active. The function returns

Additional information about the event that causes execution to resume is available through the figure's CurrentCharacter, SelectionType, and CurrentPoint properties.

If a WindowButtonDownFcn is defined for the figure, its callback is executed before waitforbuttonpress returns a value.

You can interrupt waitforbuttonpress by typing Ctrl+C, but an error results unless the function is called from within a try-catch block. You also receive an error from waitforbuttonpress if you close the figure by clicking the X close box unless you call waitforbuttonpress within a try-catch block.

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 click')
else
    disp('Key press')
end

See Also

dragrect, ginput, rbbox, waitfor

User Interface Development for related functions

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS