function KbQueueDemo(deviceIndex) %% KbQueueDemo([deviceIndex]) % Shows how to detect when the user has pressed a key. % See KbQueueCheck, KbQueueWait, KbName, KbCheck, KbWait, GetChar, CharAvail. % % The KbQueueXXX functions are low-level like KbCheck and KbWait, but, like % GetChar/CharAvail, they use a queue so that brief events can be captured. % % Like GetChar/CharAvail, KbQueueXXX functions may be used % asychronously - the OS will pick up the character whether your code % is currently looking for it or not so long as the queue has already been % created(using KbQueueCreate) and started (using KbQueueStart). % % Unlike GetChar/CharAvail, KbQueueXXX functions can detect isolated presses % of modifier keys. Also, the times of key presses should be more accurate than % those associated with GetChar/CharAvail or with KbCheck and the timebase is % the same as that returned by GetSecs (unlike GetChar/CharAvail). % % The first four demos here are analogous to those in KbDemo.m % Roger Woods, November, 2007 % 11/03/07 rpw Wrote demos 1-5 % 05/21/12 mk Add event buffer test to demo 5. % 01/31/16 mk Suppress keypress spilling via ListenChar(-1); % 08/30/16 dcn Add exercising all options of KbQueueWait if nargin < 1 deviceIndex = []; end % Enable unified mode of KbName, so KbName accepts identical key names on % all operating systems: KbName('UnifyKeyNames'); % Prevent spilling of keystrokes into console: ListenChar(-1); %% Runs 5 demos in sequence try % Report keyboard key number for any pressed keys, including % modifier keys such as , , and