psychopy.org | Reference | Downloads | Github

Numbers on the right side of the keyboard are not working


#1

Dear,

My experiment requires a participant to enter numbers he/she has seen. The numbers on the front side of the keyboard are working, but the numbers on the right side of the keyboard are not working with this experiment although the Num lock is on. Generally, numbers on the right side of the keyboard are working except with this experiment.

Could anyone help me with this?

Best,
Sami


#2

The keys on the numerical keys registers as “num_1”, “num_2”, etc. whereas the number-keys above the letters register as “1”, “2”, etc. So to treat both equal, do something like this:

from psychopy import event
allowed_keys = ['1', '2', '3', 'num_1', 'num_2', 'num_3']
key = event.waitKeys(keyList=allowed_keys)[0]  # wait for keys and pick the first one
number = key[-1]  # take the last character in the string. '2' and 'num_2' will both become just '2'.

You could also do something more general if you just want to react to all number keys:

key = event.waitKeys()[0]  # allow all keys, pick first
try: 
    number = int(key[-1])  # convert last character to integer. ValueError if not
    print number
except ValueError:
    print 'you did not press a number!'

External numeric keypad response