Key presses not being logged with kbCheck

I have been mostly programming this task on the lab computer, my keypresses were being logged with mostly the same code (~95%, I’ve made some placement changes). Now, (on my macOS laptop; Ventura.13.2.1) it is not working. The variable keyIsDown reports no key is pressed (0) but somehow it is advancing through my loop. I have spent a couple hours trying to look at the documentation and perusing the internet, but nothing provides me to a solution. I am seeking assistance with the following issues.
Problem 1: Keypress ‘reject key’ not being logged/saved
Problem 2. The loop (trials) do not restart after the fixation screen

while KbCheck
      go = 0;
      while go == 0
      [keyIsDown, secs, keyCode] = KbCheck(-1);% read the current status of the keyboard; secs is the time of the key press
            if keyIsDown % keyIsDown is a variable that is a 1 if a key is pressed and 0 if no key is pressed
                if keyCode(accept_key)  %  logic test, if the value of keyCode corresponding to 'accept_key' is pressed
                pchoice = 1;
                trialMatrix(t,1)= cellstr(pchoice_name{pchoice}); 
-------- % some conditional statements for other keypresses follow but are not relevant to my question, so they have been removed (it's alot)

            pchoice = 2;              
                trialMatrix(t,1)= cellstr(pchoice_name{pchoice});
       Screen('TextSize',, 50);
         DrawFormattedText(, balance_string ,'center', 'center', [0 0 0]); 
                    cd('/Users/jt394/Documents/Task Code');
                     fixc= Screen('MakeTexture',, fix);
     Screen('DrawTexture',, fixc,[],[]);

Any and all help is welcomed and appreciated!

Not sure about your code specifically (indentation makes it hard to parse), but in general macOS and its paranoid security setup has all sorts of problems with PsychHID functions like KbCheck. No matter what I do to security settings for MATLAB itself, KbCheck does not work reliably. My solution is to always start MATLAB from the terminal and add terminal to the security settings. This works fine for development…

M2 Macbook Air, Ventura 13.2.1, MATLAB 2023a

Ok, I will try this, thanks!

I wish it were only paranoid, and not utterly broken. The security GUI regularly forgets settings, or gets schizophrenic, where the GUI reports settings that contradict what the OS actually does. PsychHID’s troubleshooting instructions have been improved recently to describe the rain dances one has to do, and sometimes repeatedly. Those at least worked for me on macOS 12. It seems the settings get screwed up at each update of Matlab, probably even minor bug-fix updates. Or sometimes on OS updates. The same broken security workflows affect sound input via microphone (PsychPortAudio), video capture via webcam (Screen) and possibly other stuff where user input is concerned.

The reason it usually works to launch from Terminal is because the security implementation is so bad that macOS thinks that any application launched from Terminal is the terminal, so you are actually giving these permissions to, not Octave or Matlab or Python, so as long as itself doesn’t get significant updates, it retains the permissions.

The macOS security workflow is both paranoid, and has a deeply and buggy broken UI, and is not even effective / can be circumvented by use of the terminal and scripts launched from there. More security theater than security… - Apple quality at its best.

1 Like