Skip to content

Commit

Permalink
keyboard: fix multicharacter responses in legacy/ xpyriment backend (…
Browse files Browse the repository at this point in the history
…partial fix for #736)
  • Loading branch information
smathot committed Nov 25, 2020
1 parent 48f50e1 commit 3658009
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions openexp/_keyboard/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ def _get_key_event(self, event_type):
timeout = self.timeout
while True:
time = pygame.time.get_ticks()
# Some input methods send multiple key events at the same time,
# for example when composing a multicharacter Chinese or Japanese
# string. That's why we process up all events, rather than
# assuming that there's only a single relevant event in the queue.
key = u''
for event in pygame.event.get(event_type):
if event.key == pygame.K_ESCAPE:
self.experiment.pause()
Expand All @@ -111,12 +116,12 @@ def _get_key_event(self, event_type):
else:
ucode = u''
if ucode in invalid_unicode:
key = self.key_name(event.key)
key += self.key_name(event.key)
else:
key = ucode
if keylist is None or key in keylist:
return key, time
if timeout is not None and time-start_time >= timeout:
key += ucode
if key and (keylist is None or key in keylist):
return key, time
if timeout is not None and time - start_time >= timeout:
break
return None, time

Expand Down

0 comments on commit 3658009

Please sign in to comment.