Skip to content
Advertisement

How to check for a sequence of keystrokes

I’m making a game and want to implement cheat codes like the Konami code.

But how do I check for that sequence of keystrokes?

I want it to work so that if a player just types the code it will trigger.

Thanks in advance!

Advertisement

Answer

Below is a class that checks for the Konami code, including cases such as “UP, UP, UP, DOWN, etc.”

This should work for any given sequence.

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement