-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReadKey.m
27 lines (25 loc) · 1.09 KB
/
ReadKey.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
function [key, secs] = ReadKey (KEYS)
% [key, secs] = ReadKey [(KEYS)];
% Return pressed key, or empty if no key pressed. secs is the time
% returned by KbCheck. ESC will abort execution unless it is in KEYS.
%
% If optional input KEYS, {'left' 'right'} for example, is provided, only
% provided KEYS will be detected.
%
% The key names are consistent across systems if they are shared. This
% won't distinguish keys on number pad from those number keys on main
% keyboard. To get all key names on your system, use ReadKey('KeyNames').
%
% This runs fast after first call, so it is safe to call within each video
% frame.
% 09/2005 wrote it (Xiangrui Li)
% 06/2009 added multi-key detection
% 200608 call KbEventClass, keep this only for compatibility
if nargin<1, KEYS = KbEventClass.getName('KeyNames'); end
if ischar(KEYS) && strcmpi(KEYS, 'KeyNames')
key = KbEventClass.getName(KEYS); secs = GetSecs; return;
end
[secs, key] = KbEventClass.check(KEYS);
if isempty(key), key = ''; secs = GetSecs; return; end
if ~ismember('esc', KEYS), KbEventClass.esc_exit(); end
if numel(key)==1, key = key{1}; end