My macOS is always stuck when I operate Psychtoolbox

My iMac’s system is the latest ---- Monterey 12.0.1
My iMac is Retina 5K, 27-inch, 2017.
And my Matlab is 2021a, Psychtoolbox is '‘3.0.18 - Flavor: beta - Corresponds to SVN Revision 12412’
Here’s my problem: I’ve just begun to learn Psychtoolbox and I copy the very basic example shown on the official website (the code is as below)


When I operate this simple program the screen is stuck in a grey page and whatever I do I can’t cancel or exit it.
I don’t know what’s going wrong. Maybe it’s the system bug because I can operate the same program on macOS big sur a few weeks ago.
Hoping someone can solve my problem.

macOS 12 is not officially supported or tested at all. Upgrading to a new macOS version without urgent need, given what a quality shit-show every single macOS release in the last decade was, is very brave.

Given that the script shows a grey screen, as requested, and other than that only waits for a key press, then exits, getting stuck on the grey screen suggests problems with keyboard input.

Does KbStrokeWait in the Matlab terminal work? If not, try the things posted in other threads wrt. broken macOS keyboard input.

Other than that, help PsychPaidSupportAndServices for any further advice or comments from myself.
-mario

The KbStrokeWait doesn’t work but when I changed to the keyboard with wire, it works (I used wireless keyboard before). My problem has been solved yet. Thank you.

It queries the default keyboard, so if you have multiple keyboards connected, it will only query one of them. KbStrokeWait(-1) for all of them. help KbStrokeWait for more info.