logging simultaneous key presses
I have got a problem with simultaneous key presses on one of the same stimulus.
I know that python/OS works in sequence and not in parallel. Nevertheless, I assume that on ms (or even microseconds?) two keys are very rarely pressed at the same time by human subjects.
Here is a little experiment that requires two key presses after a stimulus.
kb = keyboard(keylist = ['f','g','h','j','LSHIFT','RSHIFT','d','k'])
A = canvas()
A.text('A')
B = canvas()
B.text('B')
seq=[1,2]
print seq, len(seq), (len(seq)-1), seq[1]
seq = [A,B]*5
for i in range(10):
t = seq[i].show()
var.T_Stim = t
if seq[i] == A:
var.Stim = 'A'
elif seq[i] == B:
var.Stim ='B'
key, time = kb.get_key()
var.Resp=key
var.T_Resp=time
log.write_vars()
key, time = kb.get_key()
var.Resp=key
var.T_Resp=time
log.write_vars()
When i run the experiment i noticed that for almost simultaneous presses (difference ca. < 16ms) only one key is counted. I have to press a third time. The third is logged, together with one of the first.
An idea that came to my mind is that it might have to do with "keydown/keylift", because the first key is not lifted before the second key is pressed. I played around with this, and that is not the problem.
I am not sure whether there is a debounce interval in open sesame (in presentation you can manually set the debounce intervall, although this counts for presses of the same key only). Or does the get_key() command need so much time for processing?
Any ideas how to solve this?
Comments
Just tried it out, also happened for me sometimes when pressing the keys exactly at the same moment.
I rewrote the code a bit (see below), cleaning the indents, using two different keyboard objects and flushing them after data collection (just to be save). I had the impression that performance improved a bit although in some cases the error still occurred.
Besides, my impression was that the error was more likely to happen if one of the shift keys was involved, so it might make sense to use different keys for that. In this regard, it is also important to keep in mind that if shift is simultaneously pressed while e.g. pressing g, g will be logged as "G" in this case (which might - when ignored - lead to problems when processing the response later on).
Final remark: depending on the specific instructions for the subjects and the experimental procedure it might be more or less likely that this exact simulateneous keypresses occur or not.
Best,
Pascal
I haven't tried it out myself, but would it help if you used a
timeout
in your keyboard of 0 or maybe 1ms?Eduard
@Pascal
Thanks Pascal for your remark of the upper-case letters. I did not notice that yet. At least we know now that the presses are recognized in some way. Although not logged.
I have now changed it to LCTRL and RCTRL. (they shall press it with the left/right thumb on a laptop)
On your final remark: I actually want participants to press the keys as simultaneous as possible.
Hence the problem still exists. I need those second keypresses.
@eduard
i did not really understand how to implement timeout in my keyboard.
When i do it like this ...
key1, time1 = kb1.get_key(timeout=1)
...it only continues without any keypress. That is not what i want.
Oh sorry, that was incomplete. You would have to wrap a loop around the procedure, like this:
Eduard
@eduard YOU SAVED MY DAY!
Great this works when i set it to 0 (and if i do not use shift or ctrl).
kb1 = keyboard(keylist = ['f','g','h','j','<','-','d','k'])
kb2 = keyboard(keylist = ['f','g','h','j','<','-','d','k'])
A = canvas()
A.text('A')
B = canvas()
B.text('B')
seq = [A,B]*5
for i in range(10):
t = seq[i].show()
var.T_Stim = t
if seq[i] == A:
var.Stim = 'A'
elif seq[i] == B:
var.Stim ='B'
Now i just need to change it, so that it continues always after the thumb button.
Does OpenSesame collect key responses within the first (16) ms after a new visual stimulus is drawn?
The above mentioned script works fine on my computer at home (Win10). But in my office (Win7, uni network) from simultaneous key presses only one is registered.
Any ideas why this is the case?
Nope, I don't know. Are you using the same Opensesame version?
It was the keyboard connection. USB is too slow or sends the information something different. The old purple keyboard connection works fine.