Using multiple keyboards and monitors in an experiemnt

Hello, I’m trying to build an experiment that run on one computer with multiple screens and keyboards. I want to control of which keyboard will be listened in each routine.

keyboard.getKeyboards()

shows me I got the two keyboards connected. And ideally I want to change dynamically in a loop the device label attribute in Key Response component in the Builder, but I didn’t figure out yet what to put there, there is no label parameter in the keyboard dictionary i got. So how can I make sure only a single keyboard is active in each routine?

Also, I succeeded to using multiple monitors but only using code component and create new 2 monitor instances that keep the original monitor instance redundant. There is an option using the Builder to start with both the monitors and set for each stimuli in which monitor to present it? like $variable that I can change dynamically.

Thanks,
Nadav

I don’t believe that it is possible to select which keyboard to listen to. I’ve been working on a project where we wanted to have the participant use a button box and have the researcher’s keyboard available to type notes. Most button boxes send keypresses so we had to switch to a button box which sent a serial pulse instead.

For the monitors I think that you have to use code components to put visual stimuli on a second monitor. So, you would either need to use code for both or components for one and code for the other.

I don’t think you want to dynamically change in a loop the device label for the Key Response component, since that implicates modifying listeners at the backend. If you are doing this through an ioHub backend, then that’s doable but much less preferred in terms of runtime delays, since the ioHubServer is hosted on a separate process.

Why not use two keyboard components and update their allowed keys in each routine? Would that achieve what you need?

I need to create the functionality of 2 participants in the same computer, so in some routines player one is able to press on keyborad and in others the other player.

So its not possible to work like this? its always 2 keyboard will operate together? I cant even create using code 2 keyboard instances and listen to them manually?
What is the meaning of “Device Label” in keyboard component? seems its doesnt have any use.

Not knowing your set up, I can only make some simple suggestions:

  1. if you are running on a ‘PC’ box, you could us a parport add in card for your response buttons

  2. you could run 2 keyboards but have one set of responses on the numeric pad, and the other on the qwerty part.

  3. run 2 keyboards but separate the inputs by whether the shift or some other modifier is on.

  4. touchscreen taps for responses.

Do you need full capability to type open-ended responses?

1 Like

I think 2, 3 can be relevant, there is a way do define in PsychoPy or its just instruct the participants to do so? If there is a way to define it, how I do that? because Keyboard elements works for both keyboards in my experience.

for #2, IIRC, the returns on the numeric pad are preceded with ‘num’ e.g., 1 on the qwerty part returns ‘1’ whereas 1 on the numpad returns ‘num_1’ . If you are worried about hand positioning (or the grid layout of the numpad versus horizontal keys), you can just pop the key caps off the qwerty part and put the number caps on (for example)

qwe
asd
zxc

to simulate the keypad for one group.

as for #3, the modifiers are transient as you say, and do not differentiate keyboard. I think you might need to find an I/O handler at the USB level.

I think there might be a way to do this using Python-evdev if your platform and use-case are within its limits. Here is pressing usb dell keyboard ‘a’ then ‘1’ followed by laptop built-in keyboard ‘a’ then ‘1’

device /dev/input/event12, name "Dell Dell USB Keyboard", phys "usb-0000:03:00.3-1.1.3/input0", uniq "" event at 1729096721.375626, code 04, type 04, val 458792
device /dev/input/event12, name "Dell Dell USB Keyboard", phys "usb-0000:03:00.3-1.1.3/input0", uniq "" event at 1729096721.375626, code 28, type 01, val 00
device /dev/input/event12, name "Dell Dell USB Keyboard", phys "usb-0000:03:00.3-1.1.3/input0", uniq "" event at 1729096721.375626, code 00, type 00, val 00
device /dev/input/event12, name "Dell Dell USB Keyboard", phys "usb-0000:03:00.3-1.1.3/input0", uniq "" event at 1729096727.583632, code 04, type 04, val 458756
device /dev/input/event12, name "Dell Dell USB Keyboard", phys "usb-0000:03:00.3-1.1.3/input0", uniq "" event at 1729096727.583632, code 30, type 01, val 01
device /dev/input/event12, name "Dell Dell USB Keyboard", phys "usb-0000:03:00.3-1.1.3/input0", uniq "" event at 1729096727.583632, code 00, type 00, val 00
adevice /dev/input/event12, name "Dell Dell USB Keyboard", phys "usb-0000:03:00.3-1.1.3/input0", uniq "" event at 1729096727.647657, code 04, type 04, val 458756
device /dev/input/event12, name "Dell Dell USB Keyboard", phys "usb-0000:03:00.3-1.1.3/input0", uniq "" event at 1729096727.647657, code 30, type 01, val 00
device /dev/input/event12, name "Dell Dell USB Keyboard", phys "usb-0000:03:00.3-1.1.3/input0", uniq "" event at 1729096727.647657, code 04, type 04, val 458782
device /dev/input/event12, name "Dell Dell USB Keyboard", phys "usb-0000:03:00.3-1.1.3/input0", uniq "" event at 1729096727.647657, code 02, type 01, val 01
device /dev/input/event12, name "Dell Dell USB Keyboard", phys "usb-0000:03:00.3-1.1.3/input0", uniq "" event at 1729096727.647657, code 00, type 00, val 00
1device /dev/input/event12, name "Dell Dell USB Keyboard", phys "usb-0000:03:00.3-1.1.3/input0", uniq "" event at 1729096727.743662, code 04, type 04, val 458782
device /dev/input/event12, name "Dell Dell USB Keyboard", phys "usb-0000:03:00.3-1.1.3/input0", uniq "" event at 1729096727.743662, code 02, type 01, val 00
device /dev/input/event12, name "Dell Dell USB Keyboard", phys "usb-0000:03:00.3-1.1.3/input0", uniq "" event at 1729096727.743662, code 00, type 00, val 00
device /dev/input/event0, name "AT Translated Set 2 keyboard", phys "isa0060/serio0/input0", uniq "" event at 1729096730.111097, code 04, type 04, val 30
device /dev/input/event0, name "AT Translated Set 2 keyboard", phys "isa0060/serio0/input0", uniq "" event at 1729096730.111097, code 30, type 01, val 01
device /dev/input/event0, name "AT Translated Set 2 keyboard", phys "isa0060/serio0/input0", uniq "" event at 1729096730.111097, code 00, type 00, val 00
adevice /dev/input/event0, name "AT Translated Set 2 keyboard", phys "isa0060/serio0/input0", uniq "" event at 1729096730.178102, code 04, type 04, val 30
device /dev/input/event0, name "AT Translated Set 2 keyboard", phys "isa0060/serio0/input0", uniq "" event at 1729096730.178102, code 30, type 01, val 00
device /dev/input/event0, name "AT Translated Set 2 keyboard", phys "isa0060/serio0/input0", uniq "" event at 1729096730.178102, code 00, type 00, val 00
device /dev/input/event0, name "AT Translated Set 2 keyboard", phys "isa0060/serio0/input0", uniq "" event at 1729096730.202795, code 04, type 04, val 02
device /dev/input/event0, name "AT Translated Set 2 keyboard", phys "isa0060/serio0/input0", uniq "" event at 1729096730.202795, code 02, type 01, val 01
device /dev/input/event0, name "AT Translated Set 2 keyboard", phys "isa0060/serio0/input0", uniq "" event at 1729096730.202795, code 00, type 00, val 00
1device /dev/input/event0, name "AT Translated Set 2 keyboard", phys "isa0060/serio0/input0", uniq "" event at 1729096730.299206, code 04, type 04, val 02
device /dev/input/event0, name "AT Translated Set 2 keyboard", phys "isa0060/serio0/input0", uniq "" event at 1729096730.299206, code 02, type 01, val 00
device /dev/input/event0, name "AT Translated Set 2 keyboard", phys "isa0060/serio0/input0", uniq "" event at 1729096730.299206, code 00, type 00, val 00

You can see the ‘a’ and ‘1’ at the beginning of corresponding ‘device’ lines. The point is that the input keys are stamped with keyboard of origin. I don’t have time to work on this now, but it looks promising. The trick for you is to carefully figure out who (I mean which keyboard) is allowed to type at what time and how to buffer if you are going to want more than 1 keystroke logged. I have no idea how this will interact with psychopy either.