Cannot register keyboard input

Hi, I am trying to run a script on Matlab2022b using a M1 macbook pro. I am having trouble registering keyboard input when I open another screen
[window, windowRect] = PsychImaging(‘OpenWindow’, screenNumber, white);

cbConditionChar = Ask(window,'[FOR RESEARCHER USE ONLY] ENTER CONDITION 1 OR 2: ’ , , , ‘GetChar’, ‘center’, ‘center’);
cbCondition = str2num(cbConditionChar);

When I try to input 1 or 2 or any key, there is no response and I have to command+option+esc to quit the screen. The code works on another non-apple computer. I have looked at other posts regarding this issue and gave matlab permission in the input monitoring section in security and privacy in settings, and I tried pressing q, etc., but it is still not registering the input.

Any help would be appreciated. Thank you so much

I have an M2 and the only way I can get the keyboard to reliably work is to always run MATLAB from a terminal (I use Kitty, but iTerm or Terminal would work the same way), giving Kitty security authorisation for input monitoring and then testing with:

WaitSecs(0.01);[~,kc]=KbWait(-1);disp(KbName(kc));

Just as a reminder: PTB is not tested or supported on Apple M1/M2 etc., so things that work, work mostly by luck. E.g., visual timing can be considered completely broken and not trustworthy at all, just as with every other similar software in existence on macOS.

If I had to guess: GetChar on Matlab with GUI uses a Java based implementation on top of Matlab, whereas without GUI, it is based/emulated on top of our own keyboard queues. So probably something is broken in Matlab’s java gui backend, afaik Matlab itself is not a ARM native implementation but just Intel + Rosetta emulation.

-mario