'backslash' in keys fails online

URL of experiment: https://run.pavlovia.org/Wake/dictation/

I am using

keys = event.getKeys()
if len(keys):

with the appropriate event=psychoJS.eventManager; in code_JS

Offline backslash is registered. Online, however, it seems that it fails at the len(keys) check.

I’m trying to map a Hungarian keyboard (press the y key to advance past the instructions in the demo) and it seems that one key isn’t being presented. The student says it’s í but I can get that by pressing `. I can’t, however, get ű, and yet on the 28th December the student was able to tell me that backslash came up when they pressed ű so that suggests there has been a change in functionality since then.

This problem has reared it head again while trying to map a German keyboard

Hello wakecarter,

when I use the following code to register keypresses, I see a \ using a German keyboard:

actualKeys = event.getKeys()
n = len(actualKeys)
i = 0
while i < n:        # solange was eingegeben wurde und verarbeitet werden muss
    if actualKeys[i] == 'return':
        # pressing RETURN means time to stop
        continueRoutine = False
        break
    elif actualKeys[i] == 'backspace':
        inputText = inputText[:-1]  # lose the final character
        i = i + 1
    elif actualKeys[i] == 'z':
        inputText += 'y'
        i = i + 1
    elif actualKeys[i] == 'y':
        inputText += 'z'
        i = i + 1
    elif actualKeys[i] == 'bracketleft':
        inputText += 'ü'
        i = i + 1
    elif actualKeys[i] == 'apostrophe':
        inputText += 'ä'
        i = i + 1
    elif actualKeys[i] == 'semicolon':
        inputText += 'ö'
        i = i + 1        
    elif actualKeys[i] == 'space':
        inputText += ' '
        i = i + 1
    elif actualKeys[i] in ['minus', '-', 'num_subtract', 'Minus', 'slash']:
        inputText += '-'
        i = i + 1
    elif actualKeys[i] in ['lshift', 'rshift', 'SHIFT']:
        shift_flag = True
        i = i + 1
    else:
        if len(actualKeys[i]) == 1:
            # we only have 1 char so should be a normal key, 
            # otherwise it might be 'ctrl' or similar so ignore it
            if shift_flag:
                inputText += actualKeys[i].upper()
                shift_flag = False
            else:
                inputText += actualKeys[i]
        i = i + 1

Isn’t that your code? So, I only need the code to map z,y,ü,ä,ö.Here backslash works without code.

Best wishes Jens

On the German keyboard the character that fails is the apostrophe, so my assumption is that it uses the English backslash key.

I’ve just solved the issue (hopefully) by discovering that a keyboard component (but not event.getKeys) reports backslash as N/A

Here’s my new code in my Key Check demo.

keys = event.getKeys()
if len(keys):
    if 'return' in keys and len(displayText)>1:
        continueRoutine=False
    elif 'space' in keys:
        displayText += ' '
    elif 'backspace' in keys:
        displayText=displayText[:-1]
    elif 'lshift' in keys or 'rshift' in keys:
        modify = True
    elif modify==False:
        displayText += keys[0]
elif backslash.keys:
    if 'N/A' in backslash.keys and displayText[-1] != '\\':
        displayText += '\\'

Where backslash is a keyboard component with blank allowed keys that doesn’t end the routine.

Hello,

when I use your Key Check demo hitting the key labeled “#” give backslash as output. # and ’ (shift + #) are mapped to the same key. backslash on a German keyboard requires two keys AltGr + \.

Best wishes Jens

Is your # key to the left of your bottom row of letters? That’s where my backslash key is.

Where is your apostrophe and does that work on my key check?

Sorry – I saw you said this was Shift #

Hello,

no, the backslash is in the top row on the key right to the zero. A picture is worth a thousand words.

I should definetly clean my keyboard :rofl:

Best wishes Jens

1 Like

Thanks. I’ve realised that the issue is with the modify flag for using the shift key. My code_upper is now:

if len(keys) and modify:
            if len(keys[0])==1:
                displayText += keys[0].upper()
# displayText += keys[0].toUpperCase(); 
                thisLetter += 1
                modify = False
            elif 'backslash' in keys:
                displayText+='\''
                thisLetter += 1
                modify = False

(the commented code is how I update Both code components. I switch to Auto, then back to Both, then copy and paste the commented code to the JS side)

Hello,

on the German keyboard, you need to press AltGr and “\” at the same time to get a “\”. This doesn’t work with our demo. AltGr gives “lcontrol” and the backslash while holding the AtlGr-key gives “minus”. But it also gives “minus” when you hit the same key without holding AltGr.

Best wishes Jens
P.S. just noticed that I need to mask backslash. I edited the posts above.

Thanks. If necessary I could use a control flag in the same way I use a shift flag to modify for upper case, but so far no-one has actually needed to type a \ in my typing experiments.