Newer
Older
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
75
76
77
78
79
80
%_______________________________________________________________________
%
% Allow the experimenter to advance or exit the presentation
%_______________________________________________________________________
%
% In testing or development mode the presentation can be advanced by
% pressing expInfo.keyReturn and exited by pressing expInfo.keyEscape.
% In deployed mode the keys must be pressed in combination with a
% modifier stored in expInfo.keyModifier to prevent accidental key presses
% of the subject advancing or exiting the experiment.
%_______________________________________________________________________
%
% Input
%
% expInfo | experiment configuration generated by createDotInfo (struct)
%_______________________________________________________________________
%
% Output
%
% exitKeyPressed | expInfo.keyEscape was pressed (logical)
% resumeKeyPressed | expInfo.keyReturn was pressed (logical)
% keyIsDown | if any key, including modifiers is down (logical)
% secs | time of keypress as returned by GetSecs (numeric)
% keyCode | represents the pressed keys (array of logicals)
%_______________________________________________________________________
%
function [exitKeyPressed, resumeKeyPressed, keyIsDown, secs, keyCode] = checkKeys_byKeyB(expInfo, keyboard)
resumeKeyPressed = false;
exitKeyPressed = false;
deployed = expInfo.deployed;
[keyIsDown, secs, keyCode] = KbCheck(keyboard);
%%
%% Key codes for german/swiss-german(?) keyboard on Windows
%% LeftAlt = [18 164]
%% AltGr = [17 18 162 165]
%% LeftControl = [17 162]
%% RightControl = [17 163]
%%
%% Key codes for german/swiss-german(?) keyboard on OS X
%% LeftCmd = [227]
%% RightCmd = [231]
%%
%% On Windows Psychtoolbox returns two key codes for modifier keys.
%% For the left control key it returns 17 which is the generic key
%% code for control key and also 162 which the key code specific
%% for the left control key.
%%
%% On OS X Psychtoolbox returns a single key code for modifier keys.
%%
%% As a workaround for this inconsistency we remove the generic
%% modifier key codes for shift (16), alt (17) and control (18).
%%
if ispc
keyCodeGenMod = [16 17 18];
keyCode(keyCodeGenMod) = 0;
% if we had integer key codes, but kbcheck returns a binary key code
% keyCode = keyCode(not(ismember(keyCode,keyCodeGenMod)));
end
if keyIsDown
if deployed
keyModIsDown = any(keyCode(expInfo.keyModifier));
else
keyModIsDown = true;
end
if any(keyCode(expInfo.keyReturn))
resumeKeyPressed = true;
end
if keyModIsDown && keyCode(expInfo.keyEscape)
exitKeyPressed = true;
end
end
end