Accents in Text Input

I’m not an expert in this by any means, but the Keyboard class works by mapping the hardware code for each physical key on a keyboard to a character name. e.g. on a Mac, key code 4 corresponds to a, 5 to b, 44 to space etc, while on Windows, 65 is a, 66 is b, 32 is space, and so on.

These mappings must necessarily differ on non-US English keyboards, and even the US and British English keyboards are physically different in some key mappings. If you look inside the PsychoPy Keyboard code (which was ported from the Psychtoolbox project), you’ll see that it only provides three mappings (Windows, Mac and Linux), and doesn’t seem to provide for any internationalisation within those:

So I guess we should really aim to extend this, so that different mappings are used depending on the keyboard used, in addition to the operating system.

Where does this leave you? Well I guess you could actually just edit your local keyboard.py inside your PsychoPy app (make a copy before touching it, of course). The way to know what values to use would be to switch to the Coder view and from the Demos menu, run the input -> keyboardNEW.py demo. When pushing a key, you should see the numeric code that for Psychtoolbox (PTB) corresponds to that physical key.

e.g. I have no idea what it will be on your keyboard, but push the é key and see what number shows up (presumably the key name will be wrong). Then edit the mapping table in keyboard.py that corresponds to that number to now show the é character instead of what it currently thinks that key produces.

Could you try that for one or two characters and let us know if it works? I’m sure somewhere on the internet, tables of these values must exist, but my google skills aren’t revealing them to me at the moment, so a bit of manual checking like this might be what is required to get things to work for you at least.

1 Like