Keyboard coding/layout not recognized

Hello,

URL of experiment: https://run.pavlovia.org/jens.boelte/changeblindnessexp3/html
gitlab link: https://gitlab.pavlovia.org/jens.boelte/changeblindnessexp3

Description of the problem:

While PsychoPy recognizes a non-english keyboard layout and the non-English keys, for instance Umlauts, äÄ, öÖ, üÜ, but also ß, Pavlovia does not. On Pavolvia I get the letters/signs an English keyboard layout has isntead when punishing these keys. I use the following code to get a typed response.

var _pj;
function _pj_snippets(container) {
    function in_es6(left, right) {
        if (((right instanceof Array) || ((typeof right) === "string"))) {
            return (right.indexOf(left) > (- 1));
        } else {
            if (((right instanceof Map) || (right instanceof Set) || (right instanceof WeakMap) || (right instanceof WeakSet))) {
                return right.has(left);
            } else {
                return (left in right);
            }
        }
    }
    container["in_es6"] = in_es6;
    return container;
}
_pj = {};
_pj_snippets(_pj);
actualKeys = event.getKeys();
n = actualKeys.length;
i = 0;
while ((i < n)) {
    if ((actualKeys[i] === "return")) {
        continueRoutine = false;
        break;
    } else {
        if ((actualKeys[i] === "backspace")) {
            inputText = inputText.slice(0, (- 1));
            i = (i + 1);
        } else {
            if ((actualKeys[i] === "space")) {
                inputText += " ";
                i = (i + 1);
            } else {
                if (_pj.in_es6(actualKeys[i], ["minus", "-", "num_subtract", "Minus", "slash"])) {
                    inputText += "-";
                    i = (i + 1);
                } else {
                    if (_pj.in_es6(actualKeys[i], ["lshift", "rshift", "SHIFT"])) {
                        shift_flag = true;
                        i = (i + 1);
                    } else {
                        if ((actualKeys[i].length === 1)) {
                            if (shift_flag) {
                                inputText += actualKeys[i].toUpperCase();
                                shift_flag = false;
                            } else {
                                inputText += actualKeys[i];
                            }
                        }
                        i = (i + 1);
                    }
                }
            }
        }
    }
}

It would be really cool if the keyboard layout used on the computer would be used. How do I achieve that?

Best wishes Jens

Hi Jens,

I’ve reproduced your issue and took a little peek into the PsychoJS codebase to see if there is an easy workaround. I think we’ll need to update PsychoJS itself in order to support it. More info soon!

Best, Thomas

Hello Thomas,

thanks a lot. That would help a lot. I am looking forward to seeing this problem solved.

Best wishes Jens

How do you use this feature exactly? Here are some specific questions:

  1. Are there a specific set of keyboard responses that you’d like to register or do register any key?
  2. Can your participants have different keyboard layouts? As in: some use QWERTY, other AZERTY etc.

I use this to register typed responses in a change-blindness experiment. The keyboard-layout will be German, so that is QWERTZ. Puncation aso. is also on different keys than on an English QWERTY-keyboard.

I’d like to register any key, not just a specific set of keys.

Well, I do not know whether my participants use a different keyboard-layout. At the university, the German QWERTZ-layout is the standard. But participants might change that.

Cheers Jens

Thanks! I’ll explain a bit why I asked. So, there is a difference in how keys are registered between PsychoPy and PsychoJS. We can’t just change this, since it could break existing experiments. A nice approach could be to support both the key entities that PsychoJS returns and the actual keys that PsychoPy returns. You’d need to specify somewhere which one you want, and I’m thinking about the best way for doing that.

BTW, this could take a while to implement. Doing some Googling, I did notice there could be browser feature we might be able to use as a quick fix, but it’s only supported by Chrome and Edge. Could this help you out on the short term? https://developer.mozilla.org/en-US/docs/Web/API/Keyboard/getLayoutMap

Dear Thomas,

thanks for the explanation and the digging. I can wait.

Cheers Jens

FYI, I passed it on to out (other) devs. Here is the associated ticket on GitHub: https://github.com/psychopy/psychojs/issues/170