Problem Description: I have set up an experiment where I need to capture input from a trigger and response box, but the script fails to recognize these inputs. Strangely, other USB inputs are being detected without any issues. I have checked device connections, drivers, and permissions, but the problem persists. Besides, I can confirm that the trigger and the response box are identified by matlab with devices=PsychHID('Devices'), but the their input is not recongized.
System Information:
MATLAB Version: 2019b
Psychtoolbox Version: 3
macOS Version: 12.4 Monterey
Troubleshooting Steps Taken:
Verified device connections and cables.
Checked for the presence of proper drivers.
Examined System Information for device recognition.
Ensured MATLAB and Psychtoolbox have the necessary permissions.
Tested the trigger and response box with other software.
Code Snippet:
For instance using this code just to recognize the input, it does not have any problem if the device are either the internal keyboard (‘Apple Internal Keyboard / Trackpad’) or an external USB keyboard (‘Dell KB216 Wired Keyboard’) but it does not recognize the input if it is coming from either the response box ‘KeyWarrior8 Flex’ or the trigger (‘904’).
stringResponseBox='KeyWarrior8 Flex';
stringAppleKeyboard='Apple Internal Keyboard / Trackpad';
stringTrigger='904';
%stringTrigger='Dell KB216 Wired Keyboard';
devices=PsychHID('Devices');
KeyboardIndices=GetKeyboardIndices();
%ResponseBox
deviceIDRespbox=KeyboardIndices(strcmp({devices(KeyboardIndices).product}, ...
stringResponseBox)==1);
%Keyboard
deviceIDApple=KeyboardIndices(strcmp({devices(KeyboardIndices).product}, ...
stringAppleKeyboard)==1);
%Trigger
deviceIDTrigger=KeyboardIndices(strcmp({devices(KeyboardIndices).product}, ...
stringTrigger)==1);
% Choose the firs5123t keyboard
keyboardNumber = deviceIDRespbox; %checking the response box
KbWait(keyboardNumber);
[keyIsDown, ~, keyCode] = KbCheck(keyboardNumber);% Get the keycode of the pressed key
% Close the window
sca;
I am seeking guidance on how to troubleshoot and resolve this issue. Has anyone encountered a similar problem with Psychtoolbox 3, MATLAB 2019b, and macOS 12.4 Monterey? Any insights, suggestions, or solutions would be greatly appreciated.
Permissions in macOS is buggy or at least poorly compatible with PTB’s design, and for example for me without starting MATLAB from the terminal I cannot use the keyboard inputs at all. It seems you have access to standard keyboard inputs so that doesn’t bode well that this can be solved via the next jiggery-pokery:
Remove all permissions for MATLAB and the terminal, then re-add them, including for the terminal, then restart, then start MATLAB from terminal, then reconfirm normal keyboard inputs, then test your hardware.
You can try to increase verbosity Screen('Preference','verbosity',10); to get more logging data when the device fails to connect. Also what version of PTB, you mention V3 but that could be any release in the past many years. Do you have another Mac to test with, how about a Linux system (which are gold standard as for as things working with PTB is concerned)?
The permission management in macOS is awfully broken since the day it was introduced in macOS 10.something. But it can be made to work. What seemed to help on my machines was always completely removing Matlab from the lists in the GUI with that - Button, not just unchecking the checkbox (ie. removing the permission). Then closing everything, especially that GUI. Then manually adding Matlab via the + button and then browsing for the relevant Matlab app. This is especially necessary after each Matlab upgrade, but also if you had multiple Matlabs installed. This also applies for Apple Silicon Macs and especially for parallel installs of Intel Matlab and ARM Matlab – there can only be one functional Matlab of the same version wrt. to these permissions afaics. I wouldn’t want to think about what that means for the actual security of the security mechanism if it is that easy to confuse.
macOS security GUI design is a piece of shit, but so far I always managed to make it work at least on my test machines, so it should not be something impossible (as of Matlab R2023b and earlier, and macOS 14 and earlier) if one spends enough attempts of coercion.
But yeah, if standard keyboards work, then that’s not the reason for failure of the original poster.
Screen('Preference','verbosity',10); won’t help to diagnose PsychHID on macOS.
There’s setenv('PSYCHHID_TELLME', '1'); which may provide some extra debug output on macOS. And one would want to have the full detailed output of devices=PsychHID('Devices').
That said, I will be away for a few more weeks from my macOS machines, so can’t test or fix anything. And without paid support authentication tokens, any further help from myself will be a no go.