OS (e.g. Win10):
PsychoPy version (2021.2.0):
**Standard Standalone? y
**What are you trying to achieve?:
I want to know how a long a key was held down for before being released
**What did you try to make it work?:
For any given key I called for the key.duration attribute
**What specifically went wrong when you tried that?:
That attribute is always None
See below the code I am using inside the Each Frames tab
print(_key_mod_allKeys)
if len(_key_mod_allKeys):
print(_key_mod_allKeys[-1].name)
print(_key_mod_allKeys[-1].tDown)
print(_key_mod_allKeys[-1].duration)
And then some output
[<psychopy.hardware.keyboard.KeyPress object at 0x0000019722DABFD0>, <psychopy.hardware.keyboard.KeyPress object at 0x0000019722D9F160>]
right
281912.6402972
None
[<psychopy.hardware.keyboard.KeyPress object at 0x0000019722DABFD0>, <psychopy.hardware.keyboard.KeyPress object at 0x0000019722D9F160>]
right
281912.6402972
None
[<psychopy.hardware.keyboard.KeyPress object at 0x0000019722DABFD0>, <psychopy.hardware.keyboard.KeyPress object at 0x0000019722D9F160>, <psychopy.hardware.keyboard.KeyPress object at 0x0000019722D9F240>]
left
281912.7530118
None
You can see in this part of the output that I have just pressed a new key (the left key), having previously pressed the right key. I released the right key, and therefore the key.duration
should not be None.