Error in function KbQueueCreate; Incorrect argument type supplied

Dear developers,

This week, I created a new task in using PsychoPy Builder 2021.1.1 installed using Anaconda on Windows 10. It was working fine on my local machine.

Sometime between then and now, I updated the packages in my Anaconda environment and inadvertently updated psychopy to version 2021.1.3. When I saw this, I immediately downgraded back to psychopy 2021.1.1. When I went to work on my script today, I kept getting the following error message whenever I try to run the same task. I also tried creating an entirely new task (i.e., File > New) and tested whether it would run using one routine with (1) a text component, (2) a text and keyboard component, but get the same error message. I will include the full output.

pygame 2.0.1 (SDL 2.0.14, Python 3.6.13)
Hello from the pygame community. https://www.pygame.org/contribute.html
Error in function KbQueueCreate:        Incorrect argument type supplied
        Discrepancy between a specified and supplied argument:
                Specified Argument Description:
                        direction: Input
                        position: 6
                        presence:
                        formats allowed:
                                unclassified
                        minimum M: 1
                        maximum M: 1
                        minimum N: 1
                        maximum N: 1
                        minimum P: 1
                        maximum P: 1
                Provided Argument Description:
                        direction: Input
                        position: 6
                        presence: present
                        format: int32
                        number of dimensions: 0
                                 M: 1
                                 N: 1
                                 P: 1
PsychHID:KbQueueCreate: Usage:

PsychHID('KbQueueCreate', [deviceNumber][, keyFlags=all][, numValuators=0][, numSlots=10000][, flags=0][, windowHandle=0])
Traceback (most recent call last):
  File "multioutcome-psl-behav_lastrun.py", line 81, in <module>
    defaultKeyboard = keyboard.Keyboard()
  File "C:\Users\Shawn\.conda\envs\lsantasks\lib\site-packages\psychopy\hardware\keyboard.py", line 166, in __init__
    buffer = _keyBuffers.getBuffer(devId, bufferSize)
  File "C:\Users\Shawn\.conda\envs\lsantasks\lib\site-packages\psychopy\hardware\keyboard.py", line 356, in getBuffer
    kb_id=kb_id)
  File "C:\Users\Shawn\.conda\envs\lsantasks\lib\site-packages\psychopy\hardware\keyboard.py", line 395, in __init__
    self.dev = hid.Keyboard()  # a PTB keyboard object
  File "C:\Users\Shawn\.conda\envs\lsantasks\lib\site-packages\psychtoolbox\hid.py", line 137, in __init__
    self._create_queue(buffer_size)
  File "C:\Users\Shawn\.conda\envs\lsantasks\lib\site-packages\psychtoolbox\hid.py", line 145, in _create_queue
    None, 0, num_slots, flags, win_handle)
TypeError: Incorrect argument type supplied
0.2668  WARNING         We strongly recommend you activate the PTB sound engine in PsychoPy prefs as the preferred audio engine. Its timing is vastly superior. Your prefs are currently set to use ['sounddevice', 'PTB', 'pyo', 'pygame'] (in that order).

I have tried troubleshooting everything I could think of, including removing the Anaconda environment and recreating it from scratch. This is the environment.yml file I have been using:

name: lsantasks
channels:
  - conda-forge
dependencies:
  - python=3.6
  - psychopy=2021.1.1
  - pip
  - pip:
    - psychtoolbox
    - pygame
    - pyo
    - pyparallel; platform_system != "Windows"
    - SoundFile; platform_system == "Windows"
    - websocket_client

I have a previous version of psychopy (v2020.2.4) in a different Anaconda environment and it can successfully run new tasks without any error.

Please advise on what I can do to fix this issue.

Thanks so much for your help!

what version of psychtoolbox is installed? From your env:

import psychtoolbox as ptb
ptb.__version__

Just incase an old version got installed somehow.

Has any of the keyboard hardware changed since it stopped working? Wondering if this could be some hardware specific issue because the error seems to be very low level.

Also just wondernig if you needed to downgrade to 2021.1.1 or if you could have just kept using the latest version.

Could you also send a minimal example that causes the problem for you, or do any of the provided Coder or Builder demos also fail for you?

Thanks very much.

Hi, Sol,

I am having the same problem, I am trying to run a script I created a month ago and was working perfectly. Now I had to re-install anaconda and psychopy, and the scritp does not work anymore. It gives me the same error (see below). Do you have an idea what can it be? I appreciate your help

Error in function KbQueueCreate: Incorrect argument type supplied
Discrepancy between a specified and supplied argument:
Specified Argument Description:
direction: Input
position: 6
presence:
formats allowed:
unclassified
minimum M: 1
maximum M: 1
minimum N: 1
maximum N: 1
minimum P: 1
maximum P: 1
Provided Argument Description:
direction: Input
position: 6
presence: present
format: int32
number of dimensions: 0
M: 1
N: 1
P: 1
PsychHID:KbQueueCreate: Usage:

PsychHID(‘KbQueueCreate’, [deviceNumber][, keyFlags=all][, numValuators=0][, numSlots=10000][, flags=0][, windowHandle=0])
Traceback (most recent call last):

File “C:\Users\suyum\Documents\Forgetting_Sydney\Lab_Folder\Sydney_Forgetting\PythonScripts\2_DF_AudioScript_EN_window_UniSyd_wav_NewProtocol.py”, line 175, in
defaultKeyboard = keyboard.Keyboard() # default keyboard (e.g. to check for escape)

File “C:\Users\suyum\anaconda3\lib\site-packages\psychopy\hardware\keyboard.py”, line 166, in init
buffer = _keyBuffers.getBuffer(devId, bufferSize)

File “C:\Users\suyum\anaconda3\lib\site-packages\psychopy\hardware\keyboard.py”, line 355, in getBuffer
self[kb_id] = _KeyBuffer(bufferSize=bufferSize,

File “C:\Users\suyum\anaconda3\lib\site-packages\psychopy\hardware\keyboard.py”, line 395, in init
self.dev = hid.Keyboard() # a PTB keyboard object

File “C:\Users\suyum\anaconda3\lib\site-packages\psychtoolbox\hid.py”, line 137, in init
self._create_queue(buffer_size)

File “C:\Users\suyum\anaconda3\lib\site-packages\psychtoolbox\hid.py”, line 144, in _create_queue
PsychHID(‘KbQueueCreate’, self.device_number,

TypeError: Incorrect argument type supplied

I think there’s an issue in the Psychtoolbox<->Python glue. Install the version from last year (pip install psychtoolbox==3.0.16) in the meanwhile?

1 Like

Hi Alex,
Thank you for your reply. I tried that but it did not work, it said psychopy was not installed, then I installed psychopy and gave me the same error

Thank you for this comment. Finally I solved it. I had to downgrade my python version, install psychopy and then the version of psychtoolbox you suggested, I also had to add other dependencies that the older python version did not have. I appreciate your suggestion.

Thanks, this solved the issue on my end as well, using Python 3.9

As @aforren1 suggests, you should only have to downgrade the version of psychtoolbox being used, not reinstall the whole python env. It might help to explicitedly uninstall the current version of psychtoolbox before installing 3.0.16, although pip should be doing it anyhow:

pip uninstall psychtoolbox
pip install psychtoolbox==3.0.16
1 Like

How would I go about this in a Windows Standalone installation?

1 Like

@sol

I don’t think you can

on Windows 10, with psychopy 2021.2.3, psychtoolbox 2.0.17.8 and python 3.6.13, I got the same issue.
downgrading psychtoolbox to version 3.0.16 helped me resolve the issue.
I used for that the Anaconda prompt - which is a bash like command line interface that allows you to manage your environment as if you were in a linux distribution.
So I used the pip install psychtoolbox==3.0.16 and it successfully uninstalled the 3.0.17.8 version.
I however got this error message:

ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
psychopy 2021.2.3 requires pypiwin32; platform_system == "Windows", which is not installed.
psychopy 2021.2.3 requires python-vlc<=3.0.11115; platform_system == "Windows", which is not installed.
psychopy 2021.2.3 requires tobii-research; python_version <= "3.6", which is not installed.
psychopy 2021.2.3 requires ujson, which is not installed.
psychopy 2021.2.3 requires pyglet<1.5; platform_system != "Darwin", but you have pyglet 1.5.16 which is incompatible.

As for now, it has not created issues with my code.

I’d suggest instead updating to the latest psychtoolbox (3.0.18.0), which incorporates a workaround for the original issue and is much more recent (3.0.16 being over 2 years old). Not sure about the dependency resolver errors…

Hello there,

I’m having the same issue.I have the latest version of PsychoPy and I just re-downloaded psychtoolbox over matlab. What do you suggest I do? I am using Windows 10. Any help is appreciated!

It works on a different computer but I here is the error:

    Discrepancy between a specified and supplied argument:
        Specified Argument Description:
            direction: Input
            position: 6
            presence:
            formats allowed:
                unclassified
            minimum M: 1
            maximum M: 1
            minimum N: 1
            maximum N: 1
            minimum P: 1
            maximum P: 1
        Provided Argument Description:
            direction: Input
            position: 6
            presence: present
            format: int32
            number of dimensions: 0
                 M: 1
                 N: 1
                 P: 1
PsychHID:KbQueueCreate: Usage:

PsychHID('KbQueueCreate', [deviceNumber][, keyFlags=all][, numValuators=0][, numSlots=10000][, flags=0][, windowHandle=0])
4.1305     WARNING     We strongly recommend you activate the PTB sound engine in PsychoPy prefs as the preferred audio engine. Its timing is vastly superior. Your prefs are currently set to use ['sounddevice', 'PTB', 'pyo', 'pygame'] (in that order).
12.0691     WARNING     User requested fullscreen with size [1280  720], but screen is actually [1280, 1024]. Using actual size
Traceback (most recent call last):
  File "C:\Users\Display\Desktop\Eyelink_TripletTask\Eyelink_TripletsGame_lastrun.py", line 85, in <module>
    defaultKeyboard = keyboard.Keyboard()
  File "C:\Users\Display\AppData\Roaming\psychopy3\versions\psychopy\hardware\keyboard.py", line 166, in __init__
    buffer = _keyBuffers.getBuffer(devId, bufferSize)
  File "C:\Users\Display\AppData\Roaming\psychopy3\versions\psychopy\hardware\keyboard.py", line 356, in getBuffer
    kb_id=kb_id)
  File "C:\Users\Display\AppData\Roaming\psychopy3\versions\psychopy\hardware\keyboard.py", line 395, in __init__
    self.dev = hid.Keyboard()  # a PTB keyboard object
  File "C:\Program Files\PsychoPy\lib\site-packages\psychtoolbox\hid.py", line 137, in __init__
    self._create_queue(buffer_size)
  File "C:\Program Files\PsychoPy\lib\site-packages\psychtoolbox\hid.py", line 145, in _create_queue
    None, 0, num_slots, flags, win_handle)
TypeError: Incorrect argument type supplied
##### Experiment ended. #####