Created
July 23, 2018 19:08
-
-
Save wem3/85a8c7fdd66ae6509abc668210f7d10d to your computer and use it in GitHub Desktop.
Function for determining input device for collecting responses via Psychtoolbox
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function [ keys ] = initKeys() | |
| % % INITKEYS.m %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| % | |
| % queries PsychHID('Devices') & sets device values | |
| % in a structure called keys. | |
| % | |
| % note: you'll need to replace the vendorID with whatever works for your | |
| % keyboard. Find out by doing >> devices = PsychHID('Devices') and poking | |
| % around the devices structure | |
| % kludge for screen during multiband calibration (shortened for debug) | |
| % | |
| %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| % | |
| % author: wem3 | |
| % acknowledgements: Andrew Cho | |
| % written: 141031 | |
| % modified: 180330 ~wem3 | |
| % | |
| %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| %% set up button box / keyboard | |
| devices=PsychHID('Devices'); | |
| for deviceCount=1:length(devices), | |
| % the Harvard button box has the usageName 'Keyboard' and the product 'Celeritas Dev' | |
| if (strcmp(devices(deviceCount).usageName,'Keyboard') && strcmp(devices(deviceCount).product,'Celeritas Dev')), | |
| keys.bbox = deviceCount; | |
| keys.trigger = 46; % trigger pulse / TR signal key == 46 == KbName('+=') for Harvard scanner | |
| fprintf('button box detected\n using device #%d: %s\n',deviceCount,devices(deviceCount).product); | |
| break, | |
| % Microsoft External Keyboard | |
| elseif (strcmp(devices(deviceCount).usageName,'Keyboard') && strcmp(devices(deviceCount).manufacturer,'Microsoft')), | |
| keys.bbox = deviceCount; | |
| keys.trigger = KbName('t'); % use 't' as KbTrigger | |
| fprintf('Using Device #%d: external %s\n',deviceCount,devices(deviceCount).usageName); | |
| break, | |
| % Apple Internal Keyboard/Trackpad | |
| elseif (strcmp(devices(deviceCount).usageName,'Keyboard') && strcmp(devices(deviceCount).manufacturer,'Apple Internal Keyboard / Trackpad')), | |
| keys.bbox = deviceCount; | |
| keys.trigger = KbName('t'); % use 't' as KbTrigger | |
| fprintf('Using Device #%d: internal %s\n',deviceCount,devices(deviceCount).usageName); | |
| end | |
| end | |
| keys.b1 = KbName('1!'); % Keyboard 1 / right-hand index finger | |
| keys.b2 = KbName('2@'); % Keyboard 2 / right-hand middle finger | |
| keys.b3 = KbName('3#'); % Keyboard 3 / right-hand ring finger | |
| keys.b4 = KbName('4$'); % Keyboard 4 / right-hand pinky finger | |
| keys.b5 = KbName('5%'); % Keyboard 5 | |
| keys.b6 = KbName('6^'); % Keyboard 6 | |
| keys.b7 = KbName('7&'); % Keyboard 7 | |
| keys.b8 = KbName('8*'); % Keyboard 8 | |
| keys.b9 = KbName('9('); % Keyboard 9 | |
| keys.b0 = KbName('0)'); % Keyboard 0 / right-hand thumb | |
| keys.buttons = (30:39); | |
| keys.device = devices(deviceCount); | |
| keys.deviceNum = deviceCount; | |
| keys.space=KbName('SPACE'); | |
| keys.esc=KbName('ESCAPE'); | |
| keys.right=KbName('RightArrow'); | |
| keys.left=KbName('LeftArrow'); | |
| keys.up=KbName('UpArrow'); | |
| keys.down=KbName('DownArrow'); | |
| keys.shift=KbName('RightShift'); | |
| keys.kill = KbName('k'); | |
| % Don't uncomment!!! Placed here for handy reference. You need to implement these in your task code. | |
| % to disable detection of the trigger pulse: | |
| % olddisabledkeys=DisableKeysForKbCheck([KbName(52), KbName('0)')]) | |
| % to re-enable detection of the trigger pulse: | |
| % olddisabledkeys=DisableKeysForKbCheck([]) | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment