KbQueueXXX functions in Ubuntu

Dear members

I am having a very difficult time using KbQueueXXX functions (i.e., KbQueueCreate, KbQueueStart, KbQueueCheck, KbQueueRelease) to record key presses, kept bumping into errors while following some pretty old step-by-step instructions (e.g., Source One and Two listed at the very end of this post).

I tried to read through the psychtoolbox documentations but still confused with the information presented.
Some very basic questions such as e.g., should I call
PsychHID('KbQueueStart', device) or KbQueueStart(device) … to look for keypresses?

I was also wondering whether there is any working demo scripts or more recent sources/ tutorials that I can learn from. Thanks in advance.

My script:

%%create the Queue device and specify the allowed keys 
device =7; 
keys=[45 46];
keylist=zeros(1,256);
keylist(keys)=1;
KbQueueCreate(device,keylist);

    ...
        
KbQueueStart(device); % look for key presses within a specified time limit
    while TimeOut == 0
       [pressed, firstpress] = KbQueueCheck(device); %check response 
       if pressed
           if        firstPress(45)>0
               ...
                TimeOut = 1;
                break

           elseif     firstPress(46)>0
               ...
                TimeOut = 1;
                break
           end
       elseif TimeInLoop > 10
               ...
                TimeOut = 1;
                break
       end
    end
KbQueueRelease(device);

Error msg presented :

Error using PsychHID
Usage:

[keyIsDown, firstKeyPressTimes, firstKeyReleaseTimes, lastKeyPressTimes, lastKeyReleaseTimes]=PsychHID('KbQueueCheck' [, deviceIndex])

Error in KbQueueCheck (line 61)
  [pressed, firstPress, firstRelease, lastPress, lastRelease] = PsychHID('KbQueueCheck', deviceIndex);

Error in myscript (line 465)
           [pressed, firstpress] = KbQueueCheck(device); %check response

References

Source One
http://cbs.fas.harvard.edu/science/core-facilities/neuroimaging/information-investigators/matlabfaq
Source Two
ftp://ftp.tuebingen.mpg.de/pub/pub_dahl/stmdev10_D/Matlab6/Toolboxes/Psychtoolbox/PsychDocumentation/KbQueue.html

the principle seemed to be

  1. KbQueueCreate: create a list of keys
  2. KbQueueStart: start “waiting” for keypresses
  3. put KbQueueCheck: put this in a while loop to look for specific key presses
  4. KbQueueRelease : end the “wait”

Software environment
ubuntu 20.04.1 LTS
matlab 2019b
psychtoolbox 3.0.17

Those are links to random websites that are not maintained or vetted for correctness by us.

KbQueueDemo shows how to use keyboard queues. Your code looks in principle ok, but my first thought would be where does that magic device = 7 come from? Those numbers can change across reboots, if input devices are unplugged/replugged/plugged in etc., so a fixed number might be the wrong fixed number at any given time. help GetKeyboardIndices.

-mario