Record keypress overlapping and their duration (+ record duration of “no key press” events)

OS (e.g. Win10): Win10

Hello everyone,

Here a demo to record keys and their duration, including 2 keys overlapping : GitHub - jLenouvel/Psychopy_builder or file :
test_keypress_overlap.psyexp (10.1 KB)
It also record the duration of “no press events” (‘Null’ key) between 2 keypress events.

In my experiment, I present gratings that go either up, right or left. My participants have to continuously report what they see with the arrows on the keyboard. It is necessary that we record keys overlapping.
I have not implemented for more than 2 keys overlapping in this demo.

I used ‘kb.getKeys’ and not ‘event.getKeys’ because ‘kb.getKeys’ is more accurate than ‘event.getKeys’. The problem is that kb.getKeys only registers the key (and its duration) once it is released. In my case, the last key pressed is often released after the end of the routine, as my gratings are in motion until the end of the routine. In the case that the last key is not released before the end of the routine, I would like to record the name of the last key and its start time (and put None for its duration and stop time). Would you know how to do this please ?

So, with this demo (gratings is not moving, it is just to test the recording of keypress) , you will get in your .csv file :

- listKey :
Example of listKey : [[‘up’, 0.7406644999973651, 1.1245831999985967], [‘left’, 1.0770800999998755, 1.5886659999996482], [‘right’, 1.5404740999983915, 2.005274399998598], [‘up’, 1.9409391000008327, 2.405354599999555], [‘left’, 2.356442500000412, 3.2047930999979144], [‘right’, 3.124557899998763, 3.748375200000737], [‘up’, 3.5726269999977376, 5.013049699999101], [‘left’, 3.588830400000006, 3.860388699999021], [‘right’, 4.484784399999626, 5.013049699999101]].

It is a list of keypresses, with the name of the key, the start time (when the participant presses the key) and the end time (when the participant releases the key).

- Interval_Key2 :
Example of Interval_Key2 : [[‘up’, 0.7406644999973651, 0.3364156000025105, 1.0770800999998755, ‘up’], [‘Double’, 1.0770800999998755, 0.047503099998721154, 1.1245831999985967, ‘up’, ‘left’], [‘Null’, 1.1245831999985967, 0.4158908999997948, 1.5404740999983915, ‘Null’], [‘Double’, 1.5404740999983915, 0.04819190000125673, 1.5886659999996482, ‘left’, ‘right’], [‘Null’, 1.5886659999996482, 0.3522731000011845, 1.9409391000008327, ‘Null’], [‘Double’, 1.9409391000008327, 0.0643352999977651, 2.005274399998598, ‘right’, ‘up’], [‘Null’, 2.005274399998598, 0.3511681000018143, 2.356442500000412, ‘Null’], [‘Double’, 2.356442500000412, 0.04891209999914281, 2.405354599999555, ‘up’, ‘left’], [‘Null’, 2.405354599999555, 0.719203299999208, 3.124557899998763, ‘Null’], [‘Double’, 3.124557899998763, 0.08023519999915152, 3.2047930999979144, ‘left’, ‘right’], [‘Null’, 3.2047930999979144, 0.3678338999998232, 3.5726269999977376, ‘Null’], [‘up’, 3.5726269999977376, 0.01620340000226861, 3.588830400000006, ‘up’], [‘Double’, 3.588830400000006, 0.1595448000007309, 3.748375200000737, ‘right’, ‘left’], [‘left’, 3.748375200000737, 0.1120134999982838, 3.860388699999021, ‘left’], [‘Null’, 3.860388699999021, 0.6243957000006048, 4.484784399999626, ‘Null’], [‘Double’, 4.484784399999626, 0.5282652999994752, 5.013049699999101, ‘up’, ‘right’]].

It is a list of keypresses, with the name of the key (Null is when there is no key press), the start time and the end time. If there are 2 keys pressed, the name is “Double”, and you will find the name of the keys at the end. For example [‘Double’, 1.0770800999998755, 0.047503099998721154, 1.1245831999985967, ‘up’, ‘left’] mean that up key and left key was pressed between 1.0770800999998755 and 1.1245831999985967, and for a duration of 0.047503099998721154.

-you will get also Up_Duration etc. that calculate the total time in which the participant pressed the Up key during the routine.

Hope it will be useful and thank in advance for your help.

1 Like