Navon Task keyboard input handling

Hey guys. I’m trying to compare user keyboard input to a string but don’t seem to get it right. Can anyone tell me what the problem is?

            if event.getKeys() == (globalAnswers[2][1]):
                print('correct')
            else:
                print('wrong')

What is the value stored in globalAnswers[2][1]? The return value of event.getKeys() is a list of keys pressed. You might want to just access the first or last key that was pressed, not the whole return value.
For debugging, you could insert a logging.debug(f'event.getKeys(): {event.getKeys()}') before your if-else block. That should show you the value of event.getKeys().

Dear LukasPsy
Thank you for your reply

I’ve declared a 2d array:

globalAnswers = [[imageHH, '1'], [imageSH, '2'], [imageHS, '1'], [imageSS, '2']]

and I want to check the user’s keyboard input with the number associated with each image

So as @LukasPsy notes, you need to select just one key from getKeys or you could use the “in” comparator.

Also, you are probably evaluating this every frame which I doubt is your intention. I normally set keys=event.getKeys() and then do stuff if len(keys)

Dear @wakecarter
Thanks for your reply. This is the code:

questionMark.draw()
            win.flip()
            event.waitKeys()
            core.wait(4)

            keys = event.getKeys()
            print(keys)

            #       if image is HH:
            if i % 2 == 0 and rand == 0:
                rand = 1
                if [event.waitKeys[i] for i in (0)] == (globalAnswers[0][1]):
                    correct.draw()
                    win.flip()
                    core.wait(2)
                else:
                    wrong.draw()
                    win.flip()
                    core.wait(2)

            #       if image is SS:
            elif i % 2 == 0 and rand == 1:
                rand = 0
                if event.getKeys() == (globalAnswers[3][1]):
                    correct.draw()
                    win.flip()
                    core.wait(2)
                else:
                    wrong.draw()
                    win.flip()
                    core.wait(2)

            #       if image is HS
            if i % 2 != 0 and rand == 0:

                if keys[0] == (globalAnswers[2][1]):
                    correct.draw()
                    win.flip()
                    core.wait(2)
                else:
                    wrong.draw()
                    win.flip()
                    core.wait(2)

            #       if image is SH
            elif i % 2 != 0 and rand == 1:

                if event.getKeys() == (globalAnswers[1][1]):
                    correct.draw()
                    win.flip()
                    core.wait(2)
                else:
                    wrong.draw()
                    win.flip()
                    core.wait(2)