TL;DR
I want a form input to become visible after a user presses a specific sequence of keys. Is there an easy solution to this? Is it even possible? Are there any considerations that I should be aware of?
Background
I thought it might be fun to hide some easter eggs in my code for other devs to find.
One I thought of is an optional form input that can only be displayed when a sequence of keys pressed in order (like the word "reveal" or a directional input pattern). I would like a way that the pattern would be detected regardless of which element is in focus.
Some Complications
After searching for solutions and reading this Medium article, it has become apparent that despite how simple this problem sounds, it is probably a monumental, time-consuming mistake that I'll regret pouring hours of my life into.
Detecting user keyboard input is one thing, but checking that each consecutive keystroke is in the correct order is out of my league.
Potential Backup Solutions
For anyone else with this issue: I came up with a bunch of potential backup methods utilizing JS / jQuery that I could use to display the input, but none accept directional input and they break one or more of my original requirements.
- Using an accesskey attribute to set focus on hidden anchor and reveal the input field
- Setting focus on an invisible form input using an onload event
- Making input appear when a visible input's value is set to a specific value
- Clicking a hidden div to make it appear
- Setting focus on using its ID in a URL string