[solved] Log time and duration of simultaneous key presses
Sorry to bother you again. My question is a variant of the one I posted earlier (http://www.cogsci.nl/forum/index.php?p=/discussion/1199/solved-log-time-and-duration-of-multiple-key-presses#Item_3).
The script proposed in that discussion (see below) will record only one keypress at a time. However, I would like to be able to record both time and duration of 2 simultaneous key presses. My experiment is about music-induced emotions and when the partecipants indicate they experienced 2 different emotional states, I ask them to re-listen to the piece and press [key1] when they feel emotion [a] and [key2] when they feel emotion [b]. In both cases they have to keep the key pressed for as long as they experience that emotion.
This is the script that logs time and duration of single keypresses:
import pygame t0 = self.time() while pygame.mixer.get_busy(): response_time = self.time() - t0 for event in pygame.event.get(): if event.type == pygame.KEYDOWN: exp.log('KEYDOWN key=%s rt=%d' \ % (pygame.key.name(event.key), response_time)) if event.type == pygame.KEYUP: exp.log('KEYUP key=%s rt=%d' \ % (pygame.key.name(event.key), response_time))
However, if after I press one key (and keep it pressed) I press a second key, the latter is not recorded by the script. Is it possible to record time and duration of simultaneous keypresses?
Thank you so much for your help. I am just learning Python, but don't seem to know my way around it yet.
All the best,