Konami cheat input

Okay, this code allows a player to enter a password or cheat to skip around. Problem is I don’t know how to enter arrow keys in python. I trying to add actuators and have the text appear on screen but not sure where to add them in the script. Also, if you can’t tell, I’m completely amateur when it comes to coding. I using the code given in a tutorial by Arsenal RSL
import bge
from bge import logic, events

def main():

cont = bge.logic.getCurrentController()
own = cont.owner


keyEvents = logic.keyboard.events

hitKeys = [k for k in keyEvents \
                if keyEvents[k] == logic.KX_INPUT_JUST_ACTIVATED]
                
                
                
if hitKeys != 11:
    print(bge.events.EventToCharacter(hitKeys[0], True))
    own ["Input"] += bge.events.EventToCharacter(hitKeys[0], True)
    
userInput = own ["Input"]

if len(userInput) >= 10:
    own ["Input"] = ""
    print("not equal to correct answer")
    
if userInput == upKey, upKey, downKey, downKey, leftKey, rightKey, leftKey, rightKey, "B", "A":
    bge.logic.endGame()

main()

Have a look at this:
https://www.blender.org/api/blender_python_api_2_59_0/bge.events.html

Instead of using the characters to concatenate the input, try using string representations with this:
bge.events.EventToString(event)

Then, have the check (the ==) be for the resulting string that comes from inputting arrow keys as well.
Example:
Correct password: PASSWORD
== check: == “PKEYAKEYSKEYSKEYWKEYOKEYRKEYDKEY”

And if you wanted to get rid of the “KEY” that always appears after the keyboard button pressed, you could look online on how to substring a string in Python.

For this solution you will have to check that the user only types in a certain amount of characters, so you can’t let them type “DOWNARROWKEY” and get away with registering a down arrow key press. You’ll also have to increase userInput 's allowed length.

I tried adjusting it. It’s saying ‘list index out of range’.

import bge
from bge import logic, events

def main():

cont = bge.logic.getCurrentController()
own = cont.owner


keyEvents = logic.keyboard.events

hitKeys = [k for k in keyEvents \
                if keyEvents[k] == logic.KX_INPUT_JUST_ACTIVATED]
                
                
                
if hitKeys != 11:
    print(bge.events.EventToString(hitKeys[0], True))
    own ["Input"] += bge.events.EventToString(hitKeys[0], True)
    
userInput = own ["Input"]

if len(userInput) >= 10:
    own ["Input"] = ""
    print("not equal to correct answer")
    
if userInput == "UPARROWKEY, UPARROWKEY, DOWNARROWKEY, DOWNARROWKEY, LEFTARROWKEY, RIGHTARROWKEY, LEFTARROWKEY, RIGHTARROWKEY, BKEY, AKEY":
    bge.logic.endGame()

main()

I see a couple of problems with your code.

  1. Your check with hitkeys needs to check that the list is empty - not that it is a certain value. This is because
    an empty hitkeys list means nothing has yet been pressed. This should be why it’s saying ‘list index out of range.’

  2. Your == check string should not be comma (and/or) space separated, unless you have code that formats it that way.

Here are some other pointers:
len(userInput) checks for the length of the own[“Input”] string. Basically, own[“Input”] adds strings (which are basically your keyboard inputs) together. And of course, adding strings together gets you a string. Also, if len(userInput) >= 10: checks to see that the length of own[“Input”] is greater than 10.

Use a counter property to count how many keypresses the user makes. Add 1 to the counter every time the user presses a key.
So if you have a property called “counter”, you can do:

if hitKeys != []:
    own["counter"] += 1

Then, instead of

if len(userInput >= 10):

check that counter is greater than or equal to the desired value.

For this tutorial and for next time, I encourage you to add comments in your code as you follow along, so you (and others)
can read your code and figure stuff out more easily. It’s also a good habit to get into, especially if you’re just beginning, or even just trying out coding.

EDIT: You are also using the EventToString method wrong. It only takes in one parameter: event. So, change bge.events.EventToString(hitKeys[0], True) to bge.events.EventToString(hitKeys[0])