From 26bc8a3e9587509e8c423c28e09b592a9f306303 Mon Sep 17 00:00:00 2001 From: kleinerm Date: Fri, 5 Mar 2021 22:02:17 +0100 Subject: [PATCH] CALProjectImageSet: Make portable to non-Windows, minor robustness improvement. Using KbName() allows to get rid of the mystic key numbers. Using KbName('UnifyKeyNames') makes this also work on Linux or macOS. Moving the version checks to the top, because otherwise it would already be too late to verify. --- src/CALProjectImageSet.m | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/CALProjectImageSet.m b/src/CALProjectImageSet.m index 890f4e3..84880a9 100644 --- a/src/CALProjectImageSet.m +++ b/src/CALProjectImageSet.m @@ -26,6 +26,20 @@ obj.blank_image = uint8(zeros(obj.image_set_obj.image_params_used.image_height,... obj.image_set_obj.image_params_used.image_width)); + + try + ver_str = PsychtoolboxVersion; + catch + error('Pyschtoolbox is not installed or is improperly installed'); + end + + if str2num(ver_str(1)) < 3 + error('Pyschtoolbox version 3 is required. The installed version is %s.',ver_str); + end + + AssertOpenGL; % Assure Screen() visual stimulation is working. + KbName ('UnifyKeyNames'); % Use same key names on all operating systems. + if nargin == 3 obj.monitor_id = varargin{1}; else @@ -39,17 +53,6 @@ obj.blank_when_paused = 1; end - - try - ver_str = PsychtoolboxVersion; - catch - error('Pyschtoolbox is not installed or is improperly installed'); - end - - if str2num(ver_str(1)) < 3 - error('Pyschtoolbox version 3 is required. The installed version is %s.',ver_str); - end - sca % clear possible third screen window == screen('CloseAll') close all @@ -83,7 +86,7 @@ if wait_to_start fprintf('\n\n---------Press spacebar to start image projection--------\n\n'); - obj.pauseUntilKey(32); % 32 is spacebar + obj.pauseUntilKey(KbName('space')); % 32 is spacebar fprintf('\nStarted...\n'); end @@ -104,17 +107,17 @@ pressed_key = obj.checkKey(); - if pressed_key == 9 % if pressed key is tab, pause until spacebar is pressed again + if pressed_key == KbName('tab') % if pressed key is tab, pause until spacebar is pressed again obj.printPaused(i,toc(global_time)); if obj.blank_when_paused obj.flipBlankImage(); end - pressed_key = obj.pauseUntilKey([32,27]); - if pressed_key == 32 + pressed_key = obj.pauseUntilKey([KbName('space'), KbName('ESCAPE')]); + if pressed_key == KbName('space') obj.printResumed(); end end - if pressed_key == 27 % if pressed key is esc, exit loop + if pressed_key == KbName('ESCAPE') % if pressed key is esc, exit loop total_run_time = toc(global_time); obj.printStopped(i,total_run_time); run_flag = 0;