ratingScale: alternative/equivalent keys among respKeys&acceptKeys

I am recording key presses in fMRI, using a 5-button button-box that sends the letters B,Z,G,R,M over a USB port. I need the pressing of a key to also act as ‘Enter’. My ratingScale component is thus set up with respKeys=[‘b’,‘z’,‘g’,‘r’,‘m’] and acceptKeys=[‘b’,‘z’,‘g’,‘r’,‘m’].

I have noticed, however, that the presentation PC that I use sometimes changes its language settings randomly between English and German. The latter is the default but when the former happens to become the current language, the second button sends a Y instead of a Z, due to the corresponding keyboard layouts for these two languages.

To make my script robust against this random variation, I would like either a Y or a Z input to be recognised as the second key in the list. However, if I just add a ‘y’ to the key list, the complete list of keys gets coded from 1 to 6, whereas I’d like the coding to stay from 1 to 5, with either Z or Y being coded as 2.

Any trick I can try to achieve this? Many thanks in advance!

OS (e.g. Win10): Win 7
PsychoPy version (e.g. 1.84.x): 1.83
Standard Standalone? (y/n) y

Please let me know if more detail is needed to understand the question, thanks again for any help.

You could add a code component to the beginning of the routine to detect the default locale for the system. Hopefully it’s as simple as that. I would first tinker in a python console to see what locales you’re dealing with. Here’s what mine says:

>>>import locale
>>>locale.getdefaultlocale()
('en_US', 'utf-8') 

Supposing your computers have either ‘de_DE’ and ‘en_GB’ as possible languages, in the code component you could add this:

Begin experiment

import locale

germanKeys = ['b', 'y', 'g', 'r', 'm']
englishKeys = ['b', 'z', 'g', 'r', 'm']

currentLang = locale.getdefaultlocale()[0]

if currentLang == 'en_GB':
    myAcceptKeys = englishKeys
elif currentLang == 'de_DE':
    myAcceptKeys = germanKeys
# I personally would raise an error to prevent
# unexpected behavior
else:
    raise ValueError("Unexpected locale: {0}".format(currentLang))

Then in your ratingscale component, pass myAcceptKeys to repsKeys and acceptKeys:

respKeys=myAcceptKeys,
acceptKeys=myAcceptKeys,
2 Likes

thank should work, thanks so much Daniel.