Code covered by the BSD License  

Highlights from
MGetKey

from MGetKey by Marcello Ferro
Return the keyboard/mouse button code over figure.

MGetKey(hFig)
%MGetKey   Return the keyboard/mouse button code over figure.
%   ch = MGetKey(hFig) waits for keyboard/mouse button event over the
%   specified figure handle (hFig) and returns the ascii code of the
%   keyboard key or -1 if a mouse button was pressed (ch).
%   An empty value is returned if an error occurs.
%
%   See also waitforbuttonpress, get, CurrentCharacter
%
%   Copyright 2009 Marcello Ferro <marcello.ferro@ilc.cnr.it> 
%   Version: 1.0.0
%   Date: 10/11/2009
function ch = MGetKey(hFig) 
    ch_type = waitforbuttonpress;
    switch(ch_type)
        case 0
            % mouse
            ch = -1;
        case 1
            % keyboard
            ch = double(get(hFig, 'CurrentCharacter'));
        otherwise
            ch = [];
    end
end
    
    
    

Contact us at files@mathworks.com