File: KbQueueCheck.m

package info (click to toggle)
psychtoolbox-3 3.0.19.14.dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 86,796 kB
  • sloc: ansic: 176,245; cpp: 20,103; objc: 5,393; sh: 2,753; python: 1,397; php: 384; makefile: 193; java: 113
file content (74 lines) | stat: -rw-r--r-- 3,049 bytes parent folder | download
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
function [pressed, firstPress, firstRelease, lastPress, lastRelease] = KbQueueCheck(deviceIndex)
%  [pressed, firstPress, firstRelease, lastPress, lastRelease] = KbQueueCheck([deviceIndex])
%
%  Obtains data about keypresses on the specified device since the 
%  most recent call to this routine, KbQueueStart, or KbQueueWait
%  Clears all scored events, but unscored events that are still being
%  processed may remain in the queue
%
%  pressed: a boolean indicating whether a key has been pressed
%
%  firstPress: an array indicating the time that each key was first
%  pressed since the most recent call to KbQueueCheck or KbQueueStart
%
%  firstRelease: an array indicating the time that each key was first
%  released since the most recent call to KbQueueCheck or KbQueueStart
%
%  lastPress: an array indicating the most recent time that each key was
%  pressed since the most recent call to KbQueueCheck or KbQueueStart
%
%  lastRelease: an array indicating the most recent time that each key
%  was released since the most recent call to KbQueueCheck or 
%  KbQueueStart
%
%  For firstPress, firstRelease, lastPress and lastRelease, a time value
%  of zero indicates that no event for the corresponding key was
%  detected since the most recent call to KbQueueCheck or KbQueueStart
%
%  To identify specific keys, use KbName (e.g., KbName(firstPress)) to
%  generate a list of the keys for which the events occurred
%
%  For compatibility with KbCheck, any key codes stored in
%  ptb_kbcheck_disabledKeys (see "help DisableKeysForKbCheck"), will
%  not caused pressed to return as true and will be zeroed out in the
%  returned arrays. However, a better alternative is to specify a
%  keyList argument to KbQueueCreate. 
%
% _________________________________________________________________________
%
% See also: KbQueueCreate, KbQueueStart, KbQueueStop, KbQueueCheck,
%            KbQueueWait, KbQueueFlush, KbQueueRelease

% 8/19/07    rpw  Wrote it.
% 8/23/07    rpw  Modifications to add KbQueueFlush

if nargin < 1
    deviceIndex = [];
end

% Try to check if keyboard queue for 'deviceIndex' is reserved for our exclusive use:
if ~KbQueueReserve(3, 2, deviceIndex)
    if isempty(deviceIndex)
        deviceIndex = NaN;
    end
    error('Keyboard queue for device %i already in use by GetChar() et al. Use of GetChar and keyboard queues is mutually exclusive!', deviceIndex);
end

global ptb_kbcheck_disabledKeys;
if nargin==0
  [pressed, firstPress, firstRelease, lastPress, lastRelease] = PsychHID('KbQueueCheck');
elseif nargin > 0
  [pressed, firstPress, firstRelease, lastPress, lastRelease] = PsychHID('KbQueueCheck', deviceIndex);
end

% Any dead keys defined?
if ~isempty(ptb_kbcheck_disabledKeys)
   % Yes. Disable all dead keys - force them to 'not ever pressed or released':
   firstPress(ptb_kbcheck_disabledKeys)=0;
   firstRelease(ptb_kbcheck_disabledKeys)=0;
   lastPress(ptb_kbcheck_disabledKeys)=0;
   lastRelease(ptb_kbcheck_disabledKeys)=0;

   % Reevaluate global key down state:
   pressed = any(firstPress);
end