psychopy.org | Reference | Downloads | Github

Registering keyboard

OS (e.g. Win10):
PsychoPy version (e.g. 1.84.x):
Standard Standalone? (y/n) If not then what?:
What are you trying to achieve?:

In my anchor experiment participants have to give numeric answers to questions, e.g. a year, a temperature, length aso. I want to register only numeric answers and discard the rest (except enter to end the routine).

What did you try to make it work?:
I used the demo/textInput example to register the keypresses which worked in principle.

What specifically went wrong when you tried that?:
The problem is that when participants use the numeric keypad and the enter-key of the keypad. These keys are displayed as num_1, num_2, lcommand aso. In addition, when participants accidentially hit a cursor key, it is displayed as well. A working backspace is ok for correction.

key1

This error mesaage occurs when run online.
key

key3

Suggestions Jens

Hello,

I solved the problem of incorrect keypresses mentioned above by defining the possible keys:

keys = event.getKeys()
if len(keys):
    if keys[0].isdigit():
        text.text = text.text + keys[0]
    elif 'backspace' in keys:
        text.text = text.text[:-1]
    elif 'return' in keys and len(text.text) >= 1:
        continueRoutine = False
    elif 'num_enter' in keys and len(text.text) >= 1:
        continueRoutine = False
    elif 'num_1' in keys:
        text.text = text.text + '1'
    elif 'num_2' in keys:
        text.text = text.text + '2'
    elif 'num_3' in keys:
        text.text = text.text + '3'
    elif 'num_4' in keys:
        text.text = text.text + '4' 
    elif 'num_5' in keys:
        text.text = text.text + '5'
    elif 'num_6' in keys:
        text.text = text.text + '6'
    elif 'num_7' in keys:
        text.text = text.text + '7'
    elif 'num_8' in keys:
        text.text = text.text + '8'
    elif 'num_9' in keys:
        text.text = text.text + '9'
    elif 'num_0' in keys:
        text.text = text.text + '0' 

However when testing the experiment on pavlovia I get an error message, see screenshot

Zwischenablage01

I changed isdigit to isnumeric without success. I encounter the same error message stating that isnumeric is not defined.

Suggestions welcome

Cheers Jens